From: tshad on 22 Apr 2010 18:03 Is there a better way to write: Select * FROM #Temp WHERE MyID = (SELECT WorkID From Defaults Where EID = @EID OR MyID = (SELECT NonWorkID From Defaults Where EID = @EID I am doing 2 subqueries which looks at the same record but this is how it was written and am trying to see if there is a better way to do this with a CASE statement or would that matter? Thanks, Tom
From: Plamen Ratchev on 22 Apr 2010 18:29 Try: SELECT <columns> FROM #Temp WHERE EXISTS(SELECT * FROM Defaults WHERE EID = @EID AND MyID IN (WorkID, NonWorkID)); -- Plamen Ratchev http://www.SQLStudio.com
From: tshad on 22 Apr 2010 18:52 "Plamen Ratchev" <Plamen(a)SQLStudio.com> wrote in message news:q8WdnQRG7sdUUE3WnZ2dnUVZ_qgAAAAA(a)speakeasy.net... > Try: > > SELECT <columns> > FROM #Temp > WHERE EXISTS(SELECT * > FROM Defaults > WHERE EID = @EID > AND MyID IN (WorkID, NonWorkID)); > That looks better. I assume that is preferable to the 2 selects the initial programmer had set up. Thanks, Tom > -- > Plamen Ratchev > http://www.SQLStudio.com
|
Pages: 1 Prev: How to script all stored procedures Next: SQL 2005\2008 Hashbytes - salt key |