Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 389
  • Last Modified:

SQL Query Date help

Hello there,

i want to filter my sql server 2005 table based on datetime,so i do something like this but it does not return any rows

WHERE productid=6618 and created >= 2011-09-23 and created < = 2011-10-22

please help.

cheers
Zolf
0
zolf
Asked:
zolf
4 Solutions
 
Srm74Commented:
Hi,

First of all the dates should be in ''...

This this combination:

WHERE productid=6618 and created >= '23sep2011' and created <= '22oct2011'

Open in new window


0
 
VipulKadiaCommented:
Write as follows :

WHERE productid=6618 and CONVERT(nvarchar(10), created, 111) >= CONVERT(nvarchar(10), '2011-09-23', 111) and CONVERT(nvarchar(10), created, 111) < = CONVERT(nvarchar(10), '2011-10-22', 111)

0
 
sachinpatil10dCommented:
Try this

WHERE productid=6618 and created >= convert(datetime,'2011-09-23') and created < = convert(datetime,'2011-10-22')

Open in new window


or

WHERE productid=6618 and created between convert(datetime,'2011-09-23') and convert(datetime,'2011-10-22')

Open in new window

0
 
LowfatspreadCommented:
WHERE productid=6618 and created between '20110923 00:00:00.000'  and '20111022 23:59:59.997'
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now