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)
 Check Between dates in Dynamic query

Author  Topic 

ganeshkumar08
Posting Yak Master

187 Posts

Posted - 2010-05-13 : 06:35:30
Hi,

I have a datetime column in ClientJob table as Delivery date.
in SP, i pass 2 dates as from date and to date as input,
I need to check between dates.

Exec('Select * from ClientJob
Where deliveryDate between ' + @Fromdate + ' And '+ @toDate)

How to compare this.
Thanks


Solutions are easy. Understanding the problem, now, that's the hard part

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-05-13 : 06:41:18

Select * from ClientJob
Where deliveryDate between @Fromdate And @toDate

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

ganeshkumar08
Posting Yak Master

187 Posts

Posted - 2010-05-13 : 06:42:37
I need to comapare in dynamic query..

Solutions are easy. Understanding the problem, now, that's the hard part
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-05-13 : 08:00:58
Exec('Select * from ClientJob
Where deliveryDate between ''' + @Fromdate + ''' And '''+ @toDate + '''')


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-05-13 : 09:04:25

If the variables are of datetime datatype, convert them to varchar
Also refer this to know how single quotes work in SQL Server
http://beyondrelational.com/blogs/madhivanan/archive/2008/02/19/understanding-single-quotes.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -