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 2000 Forums
 SQL Server Development (2000)
 SQL DATE QUERY - problem

Author  Topic 

dupati1
Posting Yak Master

123 Posts

Posted - 2003-10-13 : 13:18:36
Hi All,

I need suggestions. Below is my code snippet

<%
Dim fromDate

fromDate = "%"

If LEN(TRIM(Request.Form("txtDate1"))) > 0 Then
fromDate = "%" + Request.Form("txtDate1") + "%"
End If

strSQL = SELECT * from myTable WHERE [surgeryDate] LIKE ' " & fromDate & " '

%>

I get the following error:

Error Type:
Microsoft OLE DB Provider for SQL Server (0x80040E07)
Syntax error converting datetime from character string.

In the query "surgeryDate" is the column name in the table and is in the datetime format, and
"txtDate1" is the name of the field on the form and is in the character string format.

Can anybody suggest me how to get around this problem. I am using SQL SERVER 2000 and ASP.

Thanks in Advance

Vijay

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2003-10-13 : 13:27:09
Use CONVERT or CAST. Information about both can be found in SQL Server Books Online.

This will probably work:
CONVERT(VARCHAR(50), surgerydate) LIKE ' " & fromDate & " '


Tara
Go to Top of Page

kapstav
Starting Member

1 Post

Posted - 2003-10-13 : 14:08:24
Dim fromDate

fromDate = "1/1/1700"

If LEN(TRIM(Request.Form("txtDate1"))) > 0 Then
fromDate = Request.Form("txtDate1")
End If

strSQL = "SELECT * from myTable WHERE [surgeryDate] LIKE %' " & fromDate & "%'"

Databases Rock !
Go to Top of Page

dupati1
Posting Yak Master

123 Posts

Posted - 2003-10-13 : 14:51:54
CONVERT function worked for me.

Thanks a lot.
Go to Top of Page
   

- Advertisement -