Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
HI,I have a table with a date column of datatype varchar(15) and the format is dd/mm/yyyyWhen I write the following query, it displays complete data of the table and it cannot understand I want only between '01/08/2013' and '31/08/2013'
select date,column1,column2 from table1where date between '01/08/2013' and '31/08/2013'
How to fix this? Appreciate your help.
Lamprey
Master Smack Fu Yak Hacker
4614 Posts
Posted - 2013-08-28 : 14:06:20
quote:Originally posted by learning_grsql How to fix this? Appreciate your help.
Change the datatype oin the table from VARCHAR to a DATE.
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2013-08-29 : 02:50:06
always make sure you use proper datatype for your fieldsMaking the datatype as date would require you to simply use a logic like
select [date],column1,column2 from table1where [date] >= '20130801' and [date] < '20130831'
welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs