Question : How to Query Same Table twice using 1 SQL Query ?

I want to do a Query where I basically return the following

Where Condition 1 and 2 and 3 match, return a value of 0
OR Where Condition 1 OR 2 OR 3 match, return a value of 1

Basically, If I find an EXACT Match of Data contained within 3 separate Fields, I want to return the Data as Well as a VALUE OF 0 in an additional Field eg. FieldSort.
Also, If I find a Match in ANY 1 or 2 of the 3 Fields, (a partial match) I want to return the Data as Well as a VALUE OF 1 in an additional Field eg. FieldSort.

And then Sort on the FieldSort Field - So that ANY RECORD with an EXACT match will be displayed at the Top of the Table, and Partial Matches below.

I am using multiple Tables as One Table Holds Staff Details, another their Work Details, and Another their Address Details. ALL Tables are linked via an EmployeeID Table

eg.
tblStaffDets as (tSD)
Field1 = EmployeeID
Field2 = Surname
Field3 = GivenName
Field4 = BirthDate
Field5 = Gender

tblHomeDets as (tHD)
Field1 = EmployeeID
Field2 = Address
Field3 = PostCode

tblWorkDets as (tWD)
Field1 = EmployeeID
Field2 = PositionTitle
Field3 = WorkAddress
Field3 = WorkPostCode

I want to Return the Following Fields

tSD.EmployeeID
tSD.Surname
tSD.GivenName
tSD.BirthDate
tSD.Gender
tHD.Address
tHD.PostCode
tWD.PositionTitle
tWD.WorkAddress
tWD.WorkPostCode
SortID

SortID = 0, where an Exact Match, SortID = 1, where a partial match occurs

Am currently Using MS Access 2000 as a Backend DB (code however will also be used in Delphi to run the Query)

Help would be greatly appreciated.

Answer : How to Query Same Table twice using 1 SQL Query ?

Then, the morning after the cut off date, run this script, and it will read the text file and disable the accounts.

Regards,

Rob.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const intForReading = 1
Const intForAppending = 8
strDisableAccountsFile = "\\serverxx\tracking\UsersToDisable.txt"
strDisabledReportFile = "\\serverxx\tracking\DisabledUsers.txt"
Set objOutput = objFSO.OpenTextFile(strDisabledReportFile, intForAppending, True)
Set objFile = objFSO.OpenTextFile(strDisableAccountsFile, intForReading, True)
While Not objFile.AtEndOfStream
	strUserDN = objFile.ReadLine
	If Trim(strUserDN) <> "" Then
		Set objUser = GetObject("LDAP://" & strUserDN)
		objUser.AccountDisabled = True
		objUser.SetInfo
		Set objUser = Nothing
		objOutput.WriteLine strUserDN
	End If
Wend
objFile.Close
objOutput.Close
Set objFile = Nothing
Set objOutput = Nothing
Set objFile = objFSO.CreateTextFile(strDisableAccountsFile, True)
objFile.Close
Set objFile = Nothing
MsgBox "Accounts that have been disabled have been written to " & VbCrLf & strDisabledReportsFile & VbCrLf & "and the file of users to disalbe has been cleared " & strDisableAccountsFile
Random Solutions  
 
programming4us programming4us