Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Server and date comparisons

Status
Not open for further replies.

Ovatvvon

Programmer
Feb 1, 2001
1,514
US
Evidently, I'm doing somthing wrong.

I want to compare the date in the database with a date chosen by a user on the web form. I want all records after the date the user has chosen to be displayed on the page. I used the following sql statement:

Select * From table_name WHERE ((table_name.dateSubmitted) > " & CDATE(dateMonth & "/" & dateDay & "/" & dateYear) & ")"

However, it doesn't matter if I choose a date on the web form from before the dates in the database or after them, it still returns all records in the database. How can I tell it to only return dates after the selected web form date? -Ovatvvon :-Q
 
Try...

Select * From table_name WHERE table_name.dateSubmitted > #" & CDATE(dateMonth & "/" & dateDay & "/" & dateYear) & "#" Saturday 12.00
im6.gif
im2.gif
im2.gif
20.00
im5.gif
im4.gif
im7.gif
3.00am
im8.gif
Sunday [img http
 
I had the # signs in there before when I was running it with an access database. But I thought sql server didn't use those...so I took them out. I just put them back in to confirm that though and got the following error when I did...

Microsoft OLE DB Provider for SQL Server error '80040e14'

Line 1: Incorrect syntax near '#'.

-Ovatvvon :-Q
 
Oops u right

strdate=dateMonth & "/" & dateDay & "/" & dateYear

strSQL = &quot;Select * From table_name WHERE table_name.dateSubmitted < CDATE('&quot; & strDate & &quot;')&quot; Saturday 12.00
im6.gif
im2.gif
im2.gif
20.00
im5.gif
im4.gif
im7.gif
3.00am
im8.gif
Sunday [img http
 
CDate isn't a SQL command, it must be outside of the sql command. But I know what you were getting at...

You're right, I completly forgot the appostrophies. Once I added them, it worked. Thanks! -Ovatvvon :-Q
 
1. SQL Datetime field format &quot;yyyy-mm-dd hh:mm:ss:ms&quot;
to compare &quot;mm/dd/yyyy&quot; to SQL Datetime:
&quot;SELECT * FROM Table WHERE CONVERT(varchar(10), datefield, 101) > &quot; & theMon & &quot;/&quot; & theDay & &quot;/&quot; & theYear tvuong5@cox.com
Sr. Software Developer.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top