From: tshad on
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
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

"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