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 |
Nihar
Starting Member
3 Posts |
Posted - 2006-11-15 : 14:39:26
|
Hi All,I am trying to get a result set like thisCode Facility1 Facility2----- --------- ---------abc 1 [null]def [null] 5ekg [null] 1The data to be retreived and compared is stored in three tablesHere is the dataZrEc table----------SID ctasCd1000000 31000003 21000004 21000007 21000002 21000028 21000029 11000030 1Serv Table ----------SID encntrSID1000000 20000011000003 20000021000004 20000031000007 20000041000002 10000011000028 10000271000029 50000211000030 5000023LocTrackHist table------------------ SID currFacID2000001 TOH-CC1000001 TOH-CC2000003 TOH-CC2000002 TOH-CC1000027 TOH-CC2000004 TOH-CC5000021 TOH-CC5000023 TOH-GCHere is the SQL that i have been working with, but no result select C.codeDesc, count(Zr1.SID) "TOH-CC", count (Zr2.SID) "TOH-GC" from ctasCd C, ZrEc Zr1, Serv S1, Serv EnServ1, LocTrackHist LTH1, Serv S2, Serv EnServ2, LocTrackHist LTH2, ZrEc Zr2 where LTH1.currFacID = 'TOH-CC' and EnServ1.SID = LTH1.SID and S1.encntrSID = EnServ1.SID and C.code = Zr1.ctasCd and S1.SID not in (select SID from Serv where encntrSID in(select SID from Serv where servTypeCd = 'En' and resultStsCd = 'eie') and TID = 75) and S1.SID = Zr1.SID and S1.startDtm >= '09/13/2006' and S1.startDtm <= '11/16/2006' and LTH2.currFacID = 'TOH-GC' and EnServ2.SID = LTH2.SID and S2.encntrSID = EnServ2.SID and C.code = Zr2.ctasCd and S2.SID not in (select SID from Serv where encntrSID in(select SID from Serv where servTypeCd = 'En' and resultStsCd = 'eie') and TID = 75) and S2.SID = Zr2.SID and S2.startDtm >= '09/13/2006' and S2.startDtm <= '11/16/2006' and Zr1.SID = Zr2.SID group by C.code order by C.code |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-11-15 : 14:48:16
|
Where is ctasCd table?Peter LarssonHelsingborg, Sweden |
 |
|
Nihar
Starting Member
3 Posts |
Posted - 2006-11-15 : 14:54:16
|
ctasCd------codeTable code codeDesc siteDefFlg subTable---------- ---- -------- ------------ --------- ctasCd 1 Level 1 - Resuscitation 0 [NULL]ctasCd 2 Level 2 - Emergent 0 [NULL]ctasCd 3 Level 3 - Urgent 0 [NULL]ctasCd 4 Level 4 - Less Urgent 0 [NULL]ctasCd 5 Level 5 - Non Urgent 0 [NULL] |
 |
|
PSamsig
Constraint Violating Yak Guru
384 Posts |
Posted - 2006-11-16 : 02:28:26
|
You dont really make it easy to help you, the expected output has little to do with the given data and the query uses unspecified coloumns and deprecated JOIN notaion.But despite all that, is this by any chance what you were trying toachive?SELECT C.codeDesc ,COUNT(CASE WHEN LTH.currFacID = 'TOH-CC' THEN Zr.SID END) AS [TOH-CC] ,COUNT(CASE WHEN LTH.currFacID = 'TOH-GC' THEN Zr.SID END) AS [TOH-GC]FROM ctasCd CLEFT OUTER JOIN ZrEc ZrON Zr.ctasCd = C.codeLEFT OUTER JOIN Serv SON S.SID = Zr.SIDLEFT OUTER JOIN Serv EnServON EnServ.SID = S.encntrSIDLEFT OUTER JOIN LocTrackHist LTHON LTH.SID = EnServ.SIDWHERE S.SID not in (SELECT SID from Serv where encntrSID in (SELECT SID FROM Serv WHERE servTypeCd = 'En' and resultStsCd = 'eie') AND TID = 75) and S.startDtm >= '20060913' and S.startDtm <= '20061116'GROUP BY C.codeDescORDER BY C.codeDesc -- Alice came to a fork in the road. "Which road do I take?" she asked. "Where do you want to go?" responded the Cheshire cat. "I don't know," Alice answered. "Then," said the cat, "it doesn't matter." |
 |
|
Nihar
Starting Member
3 Posts |
Posted - 2006-11-17 : 09:39:19
|
Thanks for your update, shall try it out |
 |
|
|
|
|
|
|