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)
 Dynamically include where cause

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2004-06-14 : 07:18:36
Mike writes "I would like to be able to dynamically include a where clause based on the value of a selected column. Something like the case function but in the where clause
ex:
select t1.col1, t2.col2
from table1 t1, table2 t2
where t1.colID = t2.colID
if t1.col1 = 1
and t1.col3 = some value"

LarsG
Constraint Violating Yak Guru

284 Posts

Posted - 2004-06-14 : 07:25:00
[code]
select t1.col1, t2.col2
from table1 t1, table2 t2
where t1.colID = t2.colID
and ((t1.col1 = 1
and t1.col3 = 'some value')
or coalesce(t1.col1,0) <> 1)
[/code]
Go to Top of Page

JasonGoff
Posting Yak Master

158 Posts

Posted - 2004-06-14 : 07:33:46
select t1.col1, t2.col2
from table1 t1, table2 t2
where t1.colID = t2.colID
and CASE t1.col1 WHEN 1 THEN t1.col3='some value' END

Go to Top of Page
   

- Advertisement -