473,385 Members | 2,243 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

ASP SQL - using variables in SQL select screen

I have a form that sends an ASP page the data to use for this string...
using values for "startdate", "enddate" and "lookfor" varibables...

rs.Open "SELECT * FROM TABLE WHERE dateadded >= ' & startdate & ' AND
dateadded < ' & enddate & ' AND sendemail = ' & lookfor & '"

well it works perfectly when I have the actual dates or the actual value of
"lookfor" like this example

rs.Open "SELECT * FROM TABLE WHERE dateadded >= ('6/15/2003 2:12:03 PM')
AND dateadded < ('8/15/2003 2:12:03 PM') AND sendemail = 'Y'"
but when I use the top string with variables instead of values i get error:
Microsoft OLE DB Provider for SQL Server error '80040e07'

Syntax error converting datetime from character string.

/newsstats/reports.asp, line 23
If I use response.Writes before the error happens i get what seem to be
correct values for the variables?!?!

('7/29/2003 12:00:00 AM')
('8/4/2003 12:00:00 AM')
'Y'

what am I doing wrong?? :(

--
- Ed
Jul 19 '05 #1
4 15453
You need to response.write the entire sql statement to be able to debug
this. Always assign your SQL statement to a variable so you can
response.write it. Then use the variable in your recordset open statement.

Show us the result of the response.write if you still can't figure it out.

You may want to use a stored procedure instead of building the sql statement
dynamically. It's easy to pass parameters to a procedure. In this case, you
could run a script like this to create the procedure:

CREATE PROCEDURE GetRecords (
@start datetime,
@end datetime,
@lookfor char(1) --just a guess
) As
Select col1, ...,colN FROM Table
WHERE dateadded >= @start AND
dateadded < @end AND
sendemail = @lookfor

Then in ASP, do this:
conn.GetRecords cdate(startdate), cdate(enddate), _
lookfor, rs

Bob Barrows

Ed Garcia wrote:
I have a form that sends an ASP page the data to use for this
string... using values for "startdate", "enddate" and "lookfor"
varibables...

rs.Open "SELECT * FROM TABLE WHERE dateadded >= ' & startdate & ' AND
dateadded < ' & enddate & ' AND sendemail = ' & lookfor & '"

well it works perfectly when I have the actual dates or the actual
value of "lookfor" like this example

rs.Open "SELECT * FROM TABLE WHERE dateadded >= ('6/15/2003 2:12:03
PM') AND dateadded < ('8/15/2003 2:12:03 PM') AND sendemail = 'Y'"
but when I use the top string with variables instead of values i get
error: Microsoft OLE DB Provider for SQL Server error '80040e07'

Syntax error converting datetime from character string.

/newsstats/reports.asp, line 23
If I use response.Writes before the error happens i get what seem to
be correct values for the variables?!?!

('7/29/2003 12:00:00 AM')
('8/4/2003 12:00:00 AM')
'Y'

what am I doing wrong?? :(

Jul 19 '05 #2
I swear I just heard an airplane fly above my head... did I mentioned I am
relatively new at this? :)

Ok let me thinker that you gave me a bit and try it...

--
- Ed

"Bob Barrows" <re*******@yahoo.com> wrote in message
news:ek**************@tk2msftngp13.phx.gbl...
You need to response.write the entire sql statement to be able to debug
this. Always assign your SQL statement to a variable so you can
response.write it. Then use the variable in your recordset open statement.

Show us the result of the response.write if you still can't figure it out.

You may want to use a stored procedure instead of building the sql statement dynamically. It's easy to pass parameters to a procedure. In this case, you could run a script like this to create the procedure:

CREATE PROCEDURE GetRecords (
@start datetime,
@end datetime,
@lookfor char(1) --just a guess
) As
Select col1, ...,colN FROM Table
WHERE dateadded >= @start AND
dateadded < @end AND
sendemail = @lookfor

Then in ASP, do this:
conn.GetRecords cdate(startdate), cdate(enddate), _
lookfor, rs

Bob Barrows

Ed Garcia wrote:
I have a form that sends an ASP page the data to use for this
string... using values for "startdate", "enddate" and "lookfor"
varibables...

rs.Open "SELECT * FROM TABLE WHERE dateadded >= ' & startdate & ' AND
dateadded < ' & enddate & ' AND sendemail = ' & lookfor & '"

well it works perfectly when I have the actual dates or the actual
value of "lookfor" like this example

rs.Open "SELECT * FROM TABLE WHERE dateadded >= ('6/15/2003 2:12:03
PM') AND dateadded < ('8/15/2003 2:12:03 PM') AND sendemail = 'Y'"
but when I use the top string with variables instead of values i get
error: Microsoft OLE DB Provider for SQL Server error '80040e07'

Syntax error converting datetime from character string.

/newsstats/reports.asp, line 23
If I use response.Writes before the error happens i get what seem to
be correct values for the variables?!?!

('7/29/2003 12:00:00 AM')
('8/4/2003 12:00:00 AM')
'Y'

what am I doing wrong?? :(


Jul 19 '05 #3
thanks for the tip of making this a complete sql statement before tyring to
actually get it... it worked after I did this...

selectstring = "SELECT * FROM TABLE WHERE dateadded >= " + startdate + "
AND lastvisit < " + enddate + " AND sendemail = '" + lookfor + "'"

rs.Open (selectstring), sConnString, 3

--
- Ed
"Ed Garcia" <ed@askme.com> wrote in message
news:Ov**************@TK2MSFTNGP09.phx.gbl...
I swear I just heard an airplane fly above my head... did I mentioned I am
relatively new at this? :)

Ok let me thinker that you gave me a bit and try it...

--
- Ed

"Bob Barrows" <re*******@yahoo.com> wrote in message
news:ek**************@tk2msftngp13.phx.gbl...
You need to response.write the entire sql statement to be able to debug
this. Always assign your SQL statement to a variable so you can
response.write it. Then use the variable in your recordset open statement.
Show us the result of the response.write if you still can't figure it out.
You may want to use a stored procedure instead of building the sql

statement
dynamically. It's easy to pass parameters to a procedure. In this case,

you
could run a script like this to create the procedure:

CREATE PROCEDURE GetRecords (
@start datetime,
@end datetime,
@lookfor char(1) --just a guess
) As
Select col1, ...,colN FROM Table
WHERE dateadded >= @start AND
dateadded < @end AND
sendemail = @lookfor

Then in ASP, do this:
conn.GetRecords cdate(startdate), cdate(enddate), _
lookfor, rs

Bob Barrows

Ed Garcia wrote:
I have a form that sends an ASP page the data to use for this
string... using values for "startdate", "enddate" and "lookfor"
varibables...

rs.Open "SELECT * FROM TABLE WHERE dateadded >= ' & startdate & ' AND
dateadded < ' & enddate & ' AND sendemail = ' & lookfor & '"

well it works perfectly when I have the actual dates or the actual
value of "lookfor" like this example

rs.Open "SELECT * FROM TABLE WHERE dateadded >= ('6/15/2003 2:12:03
PM') AND dateadded < ('8/15/2003 2:12:03 PM') AND sendemail = 'Y'"
but when I use the top string with variables instead of values i get
error: Microsoft OLE DB Provider for SQL Server error '80040e07'

Syntax error converting datetime from character string.

/newsstats/reports.asp, line 23
If I use response.Writes before the error happens i get what seem to
be correct values for the variables?!?!

('7/29/2003 12:00:00 AM')
('8/4/2003 12:00:00 AM')
'Y'

what am I doing wrong?? :(



Jul 19 '05 #4
In article <eF*************@tk2msftngp13.phx.gbl>, ed@askme.com says...
x> I have a form that sends an ASP page the data to use for this
string...
using values for "startdate", "enddate" and "lookfor" varibables... If I use response.Writes before the error happens i get what seem to be
correct values for the variables?!?!

('7/29/2003 12:00:00 AM')
('8/4/2003 12:00:00 AM')
'Y'

what am I doing wrong?? :(


If you're accessing the Jet engine, you need to surround your dates with
#-signs, or so I've heard.

-- Rick

Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Steven Scaife | last post by:
I have decided to re-write the intranet site i created over a year ago. The coding is pretty awful and hard to read cos I made the mistake of not putting comments in or putting crappy comments in...
4
by: RelaxoRy | last post by:
I have 2 screen sizes I want to accomodate for. screen.width <= 800 and > 800. This is because If it's one or the other, I want a different set of menu graphics, and to set variables for my...
12
by: Mal Ice | last post by:
I am creating an initial index.htm page on which I show some disclaimers and introduction information. In the head section I have Javascript which determines the screen resolution of the client....
0
by: Jason Steeves | last post by:
I have one .aspx form that my users fill out and this then takes that information and populates a second .aspx form via session variables. I need to screen scrape the second .aspx form and e-mail...
3
by: Sean | last post by:
Have you ever wanted to add the great features inherent in Google Maps? Here is how you do it. ============== == STEP ONE == ============== Create a new MS Access form called frmGoogleMap....
2
by: Les Peabody | last post by:
Hello. I'm a rookie ASP VBScripter and am having a difficult time scripting the following scenario: I have an index.asp file that has a multi-line text box and a button of type button. When...
8
by: Jeff Higgins | last post by:
Hi, In the variable "anchor" I would like to, (I think), use the value of the variable "text" in the predicate of the select expression. Is this possible? Is there a better way of doing...
0
by: | last post by:
I'm being driven nuts by what I'm sure is a simple solution, I have to pass some user and company id variables between 2 pages and on the second page use the params in a SQL query to list all items...
6
by: trbjr | last post by:
Hello experts, I want to describe a project design and then ask some questions at the end. There is no code in this discussion, just symbols to illustrate an idea. Let S stand for a screen...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.