Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Need to narrow my results

Author  Topic 

parallon
Starting Member

25 Posts

Posted - 2006-07-26 : 11:16:16
Hello all. I have the following query which is working good, although I need to somehow DISTINCT my results. I have tried various things, but keep getting an error.

SELECT WorkOrder.WoNum, WorkOrder.TargetDate, WorkOrder.TargetEndDate, WorkOrder.Status, WOLabour.Employee, WoLabour.TransDate
FROM WorkOrder INNER JOIN WOLabour ON WorkOrder.WoNum = WOLabour.WoNum
WHERE Workorder.TargetDate IS NOT NULL AND Workorder.TargetEndDate IS NOT NULL
AND (Workorder.Status = 'wtappr' OR Workorder.Status = 'appr')
AND WOLabour.Employee = 'ebystro'
AND WoLabour.TransDate BETWEEN Workorder.TargetDate AND Workorder.TargetEndDate
Group By WorkOrder.WoNum, WorkOrder.TargetDate, WorkOrder.TargetEndDate, WorkOrder.Status, WOLabour.Employee, WoLabour.TransDate


I tried adding the following in front of the query, but I keep getting the error "Line 10: Incorrect syntax near ')'."
SELECT DISTINCT WoNum
FROM WorkOrder
WHERE (....)


Any suggestions would be greatly appreciated.

Thanks,

Parallon

nr
SQLTeam MVY

12543 Posts

Posted - 2006-07-26 : 11:19:01
Not sure what you want. This should work
SELECT distinct WorkOrder.WoNum
FROM WorkOrder
INNER JOIN WOLabour ON WorkOrder.WoNum = WOLabour.WoNum
WHERE Workorder.TargetDate IS NOT NULL AND Workorder.TargetEndDate IS NOT NULL
AND (Workorder.Status = 'wtappr' OR Workorder.Status = 'appr')
AND WOLabour.Employee = 'ebystro'
AND WoLabour.TransDate BETWEEN Workorder.TargetDate AND Workorder.TargetEndDate


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

parallon
Starting Member

25 Posts

Posted - 2006-07-26 : 11:37:53
Awesome!!!

Thank you,

Parallon
Go to Top of Page
   

- Advertisement -