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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 SELECT all matching or ...

Author  Topic 

SamC
White Water Yakist

3467 Posts

Posted - 2005-04-26 : 08:24:10
Is there a single liner SELECT that will pull all records where ColumnA = @ColumnA but if none are found, then choose WHERE ColumnA = 0

I can't do it without using: IF EXISTS BEGIN END ELSE BEGIN END

Sam

mr_mist
Grunnio

1870 Posts

Posted - 2005-04-26 : 08:36:03
Yeah, you can do

SELECT * FROM yourtable WHERE
((SELECT count(*) as checker from yourtable WHERE columnA = @columna) = 0 AND ColumnA = 0)
OR ColumnA = @ColumnA

Though I think I wrote a more efficient way of doing this on this forum not long ago.

-------
Moo. :)
Go to Top of Page

SamC
White Water Yakist

3467 Posts

Posted - 2005-04-26 : 08:38:33
Way cool...
Go to Top of Page
   

- Advertisement -