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
 General SQL Server Forums
 Script Library
 Reterving data

Author  Topic 

satheesh
Posting Yak Master

152 Posts

Posted - 2011-01-28 : 08:26:15

Hi all

This query returns the bellow error msg.

select * from cst
where (cst.cstStartDate between 'getdate()- 330' and 'getdate()-370')

Conversion failed when converting date and/or time from character string.

I need to get the data within this range from today.Pls Help..

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-01-28 : 08:31:27
Remove the single quotes.


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 - 2011-01-28 : 09:54:07
Not only single quote, but this too

select * from cst
where (cst.cstStartDate between getdate()- 370 and getdate()-330)

Madhivanan

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

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-01-28 : 10:06:11
Alright madhi the eagle eye



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 - 2011-02-01 : 04:43:01
quote:
Originally posted by webfred

Alright madhi the eagle eye



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




Madhivanan

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

GCoe
Starting Member

1 Post

Posted - 2011-02-25 : 17:22:09
Could you explain why the second select works but the first one does not after the ticks were removed?

Thanks

g
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-02-25 : 18:06:25
Because you have to put them in the right order with BETWEEN. What goes first is the older one.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -