|
SQL Server ASP Discussions about ASP programming with Microsoft's SQL Server. For more ASP forums, see the ASP forum category. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the SQL Server ASP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
October 20th, 2004, 10:58 AM
|
Registered User
|
|
Join Date: Oct 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
SQL query from input form
I have a form with 2 text boxes for DATE entry that I want to pass into a SQL query. I keep getting error message:
Database Results Wizard Error
Description: Syntax error converting datetime from character string.
Number: -2147217913 (0x80040E07)
Source: Microsoft OLE DB Provider for SQL Server
My two text boxes are called startdate and enddate, and post into my .asp page with this SQL query.
select dispatch.dispatch,dispatch.recdate,dispatch.comple te,dispatch.invoice,salesled.prod,salesled.price,s alesled.tax1 from (salesled inner join sales on salesled.invoice=sales.invoice)inner join dispatch on dispatch.dispatch=sales.dispatch where Sales.invdate between '& Request.form(startdate)&' and '& Request.form(enddate)&' and salesled.prod <> 'HIST' order by dispatch.dispatch
I have tried putting "" around startdate and enddate.
Josh Lindsay
|
October 20th, 2004, 11:27 AM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
|
|
In what format are you passing the date values to the Query?
_________________________
- Vijay G
Strive for Perfection
|
October 20th, 2004, 11:50 AM
|
Registered User
|
|
Join Date: Oct 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I am putting this in the text box.....
3/20/2004
When I hardcode that into the sql query it works fine.
Josh Lindsay
|
October 20th, 2004, 12:05 PM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Okay, this is how it should be.
Code:
strSQL = "select dispatch.dispatch,dispatch.recdate,dispatch.complete,dispatch.invoice,
salesled.prod,salesled.price,salesled.tax1 from (salesled inner join
sales on salesled.invoice=sales.invoice)inner join dispatch on
dispatch.dispatch=sales.dispatch where Sales.invdate between '" &
Request.form(startdate) & "' and '" & Request.form(enddate)& "' and
salesled.prod <> 'HIST' order by dispatch.dispatch"
Response.write strSQL
Response.End
Just after this line do a response.write and see how the query is constructed and compare with the one that worked fine, when you hard coded. You can even copy paste the resulting Query on SQL Query analyser and see if that returns any error still.
Hope that helps.
Cheers!
_________________________
- Vijay G
Strive for Perfection
|
October 20th, 2004, 12:13 PM
|
Registered User
|
|
Join Date: Oct 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
still getting the same error message. Is there anything else you can think of?
Josh Lindsay
|
October 20th, 2004, 12:25 PM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Can you post the SQL statement that resulted from the RESPONSE.WRITE? Let me take a look at it.
_________________________
- Vijay G
Strive for Perfection
|
October 21st, 2004, 12:54 AM
|
Friend of Wrox
|
|
Join Date: Oct 2003
Posts: 463
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I think you need to extract the date, month and year parts of the value in textbox and pass it to query in the format MM/DD/YYYY. What comes from the textbox may not be in this format now.
IMO, a combination of 3 combo boxes is best for taking a date input.
|
October 21st, 2004, 09:24 AM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Hi Josh Lindsay,
Has that issue been resolved?
Cheers!
_________________________
- Vijay G
Strive for Perfection
|
|
|