Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server ASP
|
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
 
Old October 20th, 2004, 10:58 AM
Registered User
 
Join Date: Oct 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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
 
Old October 20th, 2004, 11:27 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

In what format are you passing the date values to the Query?

_________________________
- Vijay G
Strive for Perfection
 
Old October 20th, 2004, 11:50 AM
Registered User
 
Join Date: Oct 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am putting this in the text box.....
3/20/2004

When I hardcode that into the sql query it works fine.

Josh Lindsay
 
Old October 20th, 2004, 12:05 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

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
 
Old October 20th, 2004, 12:13 PM
Registered User
 
Join Date: Oct 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

still getting the same error message. Is there anything else you can think of?

Josh Lindsay
 
Old October 20th, 2004, 12:25 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Can you post the SQL statement that resulted from the RESPONSE.WRITE? Let me take a look at it.

_________________________
- Vijay G
Strive for Perfection
 
Old October 21st, 2004, 12:54 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 463
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to madhukp
Default

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.
 
Old October 21st, 2004, 09:24 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Josh Lindsay,

Has that issue been resolved?

Cheers!

_________________________
- Vijay G
Strive for Perfection





Similar Threads
Thread Thread Starter Forum Replies Last Post
pass-through query with input parmeter jimmy Access 4 February 8th, 2018 10:21 AM
Oracle connection-passing input to query!! thottufj Pro Visual Basic 2005 1 October 18th, 2007 03:21 PM
Update table using SQL query from form pater53 Access VBA 4 January 24th, 2007 11:24 AM
Form Input, Parameters, Report Based on Query DavidWE Access VBA 2 November 6th, 2006 10:36 AM
passing input to a query mirage Access 3 October 23rd, 2003 08:43 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.