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.
| Author |
Topic |
|
chrispy
Posting Yak Master
107 Posts |
Posted - 2007-07-03 : 13:59:26
|
Working on a query that I am having difficulty with.I have a TablesTABLE JobDetailsJobTitle char(50),JobID intand TABLE JobsActiveLocID int,JobID intI am working on a stored procedure and passing the @LocID var to it. I am trying to create a select with all the JobTitles but an addition column called 'Active'.So if I have this dataJobDetails:JobID JobTitle----- --------1 SalesPerson2 Cashier3 Shipper4 ManagerJobsActive:LocID JobID----- -------333 1333 2999 4888 2 And I passed the @LocID of 333 This is what I need in return.Result Set:JobID JobTitle Active------ -------- ------1 Salesperson 12 Cashier 13 Shipper 04 Manager 0 Hopefully that makes sense. For the active it will be used in a Boolean expression, so I could care less about the 0 being returned, heck the '1' could even be the LocID.Hope this makes sense. Thanks!!!!!!!!! |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-07-03 : 19:23:59
|
use LEFT JOINSELECT j.JobID, j.JobTitle, Active = CASE a.JobID IS NOT NULL THEN 1 ELSE 0 ENDFROM JobDetails j LEFT JOIN JobsActive a ON j.JobID = a.JobID AND a.LocID = @LocID KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
chrispy
Posting Yak Master
107 Posts |
Posted - 2007-07-03 : 19:31:43
|
| khtan,Thanks for the Idea. I just got this working,as you responded, but was using a temp table. Your way is much better and I will use that!!!Thanks a million. |
 |
|
|
|
|
|