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 2005 Forums
 Transact-SQL (2005)
 Dynamic Where Clause

Author  Topic 

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2009-08-06 : 05:24:36
Hi friends,

I want to build a query with dynamic where clause, some thing like this

Select * from mytable
Where case when @start_date_in is not null then start_time>=@start_date_in else 1=1 end

Can u help to get this?




Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-08-06 : 05:28:12
Select * from mytable
Where (@start_date_in is null or start_time >= @start_date_in)



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2009-08-06 : 05:34:03
quote:
Originally posted by Peso

Select * from mytable
Where (@start_date_in is null or start_time >= @start_date_in)



N 56°04'39.26"
E 12°55'05.63"




Thanks Peter it helps me alot.

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page
   

- Advertisement -