SunQuest
           ASP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreASP Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old September 19th, 2003, 07:30 PM
craigg3 craigg3 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Beaumont, Tx
Posts: 20 craigg3 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 51 m 14 sec
Reputation Power: 0
Help with SQL Statement

Trying to get this SQL statement to work, but still fairly new to writing SQL statements. The code above and below the commented lines work, just cant get the line of code in between to work. Can someone please help? Thanks.

SQL_ITEMS = "SELECT * "_
&"From Autos " _
&"WHERE Category LIKE '"_
& Request("selCategory1")_
&"%' "_
&"AND Type LIKE '%"_
& Request("selType") _
&"%' "_
&"AND ItemName LIKE '%"_
& ItemName _
&"%' "_
&"AND Description LIKE '%"_
& ItemDesc _
&"%' "_
'''''''''this is the part im having problems with
&"AND Year >= Request("selYearFrom")
&"AND Year <= Request("selYearTo")
&"AND Price >= Request("selPriceFrom")
&"AND Price <= Request("selPriceTo")
''''''''''''''''''''''''''''''''''''''''''''''''''
&"AND DatePlaced + 45 >= Now()"_
&"Order By DatePlaced DESC;"

Reply With Quote
  #2  
Old September 19th, 2003, 07:43 PM
Doug G Doug G is offline
Grumpier Old Moderator
Dev Shed God 12th Plane (10500 - 10999 posts)
 
Join Date: Jun 2003
Posts: 10,703 Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level) 
Time spent in forums: 4 Weeks 1 Day 21 h 25 m 29 sec
Reputation Power: 688
Try this

&"AND Year >='" & Request("selYearFrom") & "'"
&"AND Year <= '" & Request("selYearTo") & "'"
&"AND Price >= " & Request("selPriceFrom")
&"AND Price <= " & Request("selPriceTo")

Also, it is dangerous to let user data get into your sql statment without being filtered by your code. You should inspect the data coming from request("whatever") to prevent sql injection attacks & data errors.

Reply With Quote
  #3  
Old September 19th, 2003, 07:49 PM
craigg3 craigg3 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Beaumont, Tx
Posts: 20 craigg3 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 51 m 14 sec
Reputation Power: 0
Doug, I tried the code and this is the error I get

&"AND Year <= '" & Request("selYearTo") & "'"
^

The ^ sign appears under the first & sign.

Reply With Quote
  #4  
Old September 20th, 2003, 09:49 AM
unatratnag unatratnag is offline
Average Intelligence
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2003
Location: Ohio/Chicago
Posts: 678 unatratnag User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 m 22 sec
Reputation Power: 6
Send a message via AIM to unatratnag
his code should work, just make sure you add the concatenate operator at the end to continue the string to the next line.

also you have comments after and before the part that's not working. I don't think you can continue a line with a comment inbetween, you'd have to remove the comment or on the link after the comments continue the string with string = string & "...." i think.

Reply With Quote
  #5  
Old September 24th, 2003, 11:44 AM
davegerard davegerard is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 15 davegerard User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 35 m 5 sec
Reputation Power: 0
I take it that you'd like to show records that are less then 45 days old right? This is using MsSql as your database. The date portion of the select statement would be slightly different for Access. Hope it's close to what you're looking for.

<%
set db = server.createobject("adodb.connection")
db.connectionString = "provider=sqloledb.1; user id=MyUserId; password=MyPassword; data source=MyServer; initial catalog=MyDatabase"
db.mode=3
db.cursorlocation=3
db.open

SelCategory1 = request("selCategory1")
SelType = request("selType")
ItemName = request("ItemName")
ItemDesc = request("ItemDesc")
SelYearFrom = request("SelYearFrom")
SelYearTo = request("SelYearTo")
SelPriceFrom = request("SelPriceFrom")
SelPriceTo = request("SelPriceTo")
MyDate = Date()-45

sql = "select * from Autos"
sql = sql & " where Category LIKE '" & SelCategory1 & "%' "
sql = sql & " and Type LIKE '%" & Request("selType") & "%' "
sql = sql & " and ItemName LIKE '%" & ItemName & "%' "
sql = sql & " and Description LIKE '%" & ItemDesc & "%' "
sql = sql & " and Year >= '" & SelYearFrom & "'"
sql = sql & " and Year <= '" & SelYearTo & "'"
sql = sql & " and Price >= '" & SelPriceFrom & "'"
sql = sql & " and Price <= '" & SelPriceTo & "'"
sql = sql & " and DatePlaced <= '" & MyDate & "'"
sql = sql & " order by DatePlaced desc"
rs.open sql, db
if not rs.eof then
do while not rs.eof
response.write rs("Field1") & "<br>"
rs.movenext
loop
end if
rs.close
set rs = nothing
%>

Reply With Quote
  #6  
Old September 24th, 2003, 11:47 AM
davegerard davegerard is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 15 davegerard User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 35 m 5 sec
Reputation Power: 0
Oops! Change...

sql = sql & " and Type LIKE '%" & Request("selType") & "%' "

To

sql = sql & " and Type LIKE '%" & SelType & "%' "

Reply With Quote
  #7  
Old September 24th, 2003, 11:50 AM
davegerard davegerard is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 15 davegerard User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 35 m 5 sec
Reputation Power: 0
Oops! Try this again...

<%
set db = server.createobject("adodb.connection")
db.connectionString = "provider=sqloledb.1; user id=MyUserId; password=MyPassword; data source=MyServer; initial catalog=MyDatabase"
db.mode=3
db.cursorlocation=3
db.open

SelCategory1 = request("selCategory1")
SelType = request("selType")
ItemName = request("ItemName")
ItemDesc = request("ItemDesc")
SelYearFrom = request("SelYearFrom")
SelYearTo = request("SelYearTo")
SelPriceFrom = request("SelPriceFrom")
SelPriceTo = request("SelPriceTo")
MyDate = Date()-45

sql = "select * from Autos"
sql = sql & " where Category LIKE '" & SelCategory1 & "%'"
sql = sql & " and Type LIKE '%" & SelType & "%'"
sql = sql & " and ItemName LIKE '%" & ItemName & "%'"
sql = sql & " and Description LIKE '%" & ItemDesc & "%'"
sql = sql & " and Year >= '" & SelYearFrom & "'"
sql = sql & " and Year <= '" & SelYearTo & "'"
sql = sql & " and Price >= '" & SelPriceFrom & "'"
sql = sql & " and Price <= '" & SelPriceTo & "'"
sql = sql & " and DatePlaced <= '" & MyDate & "'"
sql = sql & " order by DatePlaced desc"
rs.open sql, db
if not rs.eof then
do while not rs.eof
response.write rs("Field1") & "<br>"
rs.movenext
loop
end if
rs.close
set rs = nothing
%>

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreASP Programming > Help with SQL Statement


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway