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 2008 Forums
 Transact-SQL (2008)
 Date Query

Author  Topic 

hussein
Starting Member

1 Post

Posted - 2012-09-04 : 17:48:10
Hi,every one
I want help

I use vb6 and sql server2000
I use the query
sql = "SELECT * from Patients WHERE (Stat_ID = " & rss!Stat_ID & _
'"AND T_Date <= '" & Date1 & "' AND T_Date >= '" & Date2 & "') ORDER BY Stat_ID "

where Date1 & Date2 date entered by the users
but the result is 0

pls help

chadmat
The Chadinator

1974 Posts

Posted - 2012-09-04 : 18:15:21
Is Date1 the End Date and Date2 the Start Date for the Range? If not, you have it backwards. Also, use between, easier to avoid mistakes like that.

-Chad
Go to Top of Page

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-09-04 : 20:26:24
quote:
Originally posted by hussein

Hi,every one
I want help

I use vb6 and sql server2000
I use the query
sql = "SELECT * from Patients WHERE (Stat_ID = " & rss!Stat_ID & _
'"AND T_Date <= '" & Date1 & "' AND T_Date >= '" & Date2 & "') ORDER BY Stat_ID "

where Date1 & Date2 date entered by the users
but the result is 0

pls help

Your sql statement has five single quotes - which means there is some sort of syntax error in it. I would guess that your statement should be one of these two:
sql = "SELECT * from Patients WHERE (Stat_ID = " & rss!Stat_ID & _
" AND T_Date <= '" & Date1 & "' AND T_Date >= '" & Date2 & "') ORDER BY Stat_ID "

sql = "SELECT * from Patients WHERE (Stat_ID = '" & rss!Stat_ID & _
"' AND T_Date <= '" & Date1 & "' AND T_Date >= '" & Date2 & "') ORDER BY Stat_ID "
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-09-05 : 21:50:13
one more thing to note. does T_Date field have time part?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2012-09-13 : 04:55:22
quote:
Originally posted by chadmat

Is Date1 the End Date and Date2 the Start Date for the Range? If not, you have it backwards. Also, use between, easier to avoid mistakes like that.

-Chad


Between may not be useful if you want to have time included

Madhivanan

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

- Advertisement -