Query returning wrong data

livvie

Registered User.
Local time
Today, 05:27
Joined
May 7, 2004
Messages
158
This query is returning records that have leaving dates - it works ok if it is just LEAVEDATE IS NULL but it doesn;t work when I add the other criteria.

SELECT REF, INITIALS + ' ' + SURNAME AS Employee, DEPTCODE, LEAVEDATE
FROM dbo.vwAllEmps
WHERE (LEAVEDATE IS NULL) AND (DEPTCODE = 'CNCM') OR
(DEPTCODE = 'PROD') OR
(DEPTCODE = 'WIRE') OR
(DEPTCODE = 'SLID') OR
(DEPTCODE = 'TOOL') OR
(DEPTCODE = 'CNCT')
 
SELECT REF, INITIALS + ' ' + SURNAME AS Employee, DEPTCODE, LEAVEDATE
FROM dbo.vwAllEmps
WHERE (LEAVEDATE IS NULL) AND ((DEPTCODE = 'CNCM') OR
(DEPTCODE = 'PROD') OR
(DEPTCODE = 'WIRE') OR
(DEPTCODE = 'SLID') OR
(DEPTCODE = 'TOOL') OR
(DEPTCODE = 'CNCT'))


???
ken
 
SELECT REF, INITIALS + " " + SURNAME AS Employee, DEPTCODE, LEAVEDATE
FROM dbo.vwAllEmps
WHERE LEAVEDATE IS NULL AND DEPTCODE In ("CNCM", "PROD", "WIRE", "SLID", "TOOL", "CNCT");
 
Thanks works fine with the extra brackets
 
Mile-O-Phile said:
SELECT REF, INITIALS + " " + SURNAME AS Employee, DEPTCODE, LEAVEDATE
FROM dbo.vwAllEmps
WHERE LEAVEDATE IS NULL AND DEPTCODE In ("CNCM", "PROD", "WIRE", "SLID", "TOOL", "CNCT");


Is there something like this 'In' statement in vba?

ken
 
KenHigg said:
Is there something like this 'In' statement in vba?

SELECT CASE is the nearest.

i.e.

Code:
Select Case DEPTCODE 
    Case Is = "CNCM", "PROD", "WIRE", "SLID", "TOOL", "CNCT"
        ' do something
    Case Else
        ' do soemthing else
End Select
 

Users who are viewing this thread

Back
Top Bottom