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)
 date between

Author  Topic 

Deep123
Starting Member

8 Posts

Posted - 2009-06-17 : 07:54:19
this is not working for me pls help

select * FROM documents where uploadeddate between '23/5/2009'
and '11/7/2009'

and uploadedate col is no datetime its an varchar

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-06-17 : 08:00:32
declare @fromdate datetime,@todate datetime
select @fromdate ='5/23/2009' ,@todate = '7/11/2009'

select * FROM documents where dateadd(d,datediff(d,0,uploadeddate),0) between @fromdate and @todate

use dateformat as mm/dd/yyyy or universal format
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-06-17 : 08:00:39
What datetype is UploadedDate?


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

Nageswar9
Aged Yak Warrior

600 Posts

Posted - 2009-06-17 : 08:03:45
it is varchar, use bklr's solution it is useful for u
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-06-17 : 08:04:41
And for the 100th time bklr, DO NOT apply functions over a column that might be indexed.
You render the index useless and the query may take ages to run, because the query engine has to scan the table instead of searching.



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

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-06-17 : 08:06:53
Deep123, why are you using varchar to store dates?
What is the reason behind this decision?



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

Deep123
Starting Member

8 Posts

Posted - 2009-06-17 : 08:10:49
quote:
Originally posted by Peso

Deep123, why are you using varchar to store dates?
What is the reason behind this decision?



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




it has been set before i cant chnge it now
one reason is tht if empty date inserted then it takes tht day date
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-06-17 : 08:14:35
That can be fixed by adding a default value.
But if "it" takes todays' date, why not add a computed column?

I guess you search a lot from this table with help of date ranges?


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

- Advertisement -