Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > SQL string problem

Reply
Thread Tools

SQL string problem

 
 
Randy
Guest
Posts: n/a
 
      01-14-2008
For the life of me, I can't figure out how to correctly punctuate the end
of this statement!
..ASP classic. Access 2000 database (I'm stuck with this for the time being)

When I in an actual value (2052 in this case) as follows:

Recset.Open "SELECT URL.TITLE, URL.ID, URL.URL from URL, BOATTOURL WHERE
URL.ID = 2052", CONN, 2, 3

It works fine and finds all appropriate records.

I just can't figure out how to put the request.querystring in there as
below. I've put in every comination of single, double, triple quotes I can
think of and just won't work.

Recset.Open "SELECT URL.TITLE, URL.ID, URL.URL from URL, BOATTOURL WHERE
URL.ID = URL_ID AND CLASS_ID = Clng(Request.QueryString("class_ID"))'"',
CONN, 2, 3

(this would normally be on one continuous line).

It's a numeric value being passed from a previous page.

As you can tell, I'm not too experienced with .asp OR SQL.

Hope this is enough info and thanks to anyone who would care to take the
time to look at it.


 
Reply With Quote
 
 
 
 
Bob Barrows [MVP]
Guest
Posts: n/a
 
      01-14-2008
Randy wrote:
> For the life of me, I can't figure out how to correctly punctuate
> the end of this statement!
> .ASP classic. Access 2000 database (I'm stuck with this for the time
> being)
> When I in an actual value (2052 in this case) as follows:
>
> Recset.Open "SELECT URL.TITLE, URL.ID, URL.URL from URL, BOATTOURL
> WHERE URL.ID = 2052", CONN, 2, 3


??? Is there no link between URL and BOATTOURL? You're getting a cartesian
join here. Is that really what is intended? Actually, why does BOATTOURL
even appear in this sql statement? You're not retrieving any information
from it ...

>
> It works fine and finds all appropriate records.
>
> I just can't figure out how to put the request.querystring in there as
> below. I've put in every comination of single, double, triple quotes
> I can think of and just won't work.
>
> Recset.Open "SELECT URL.TITLE, URL.ID, URL.URL from URL, BOATTOURL
> WHERE URL.ID = URL_ID AND CLASS_ID =


Is URL_ID in BOATTOURL? if so, the correct syntax to use is JOIN, or more
explicitly, INNER JOIN. See below.

So the idea is to only retrieve information from URL if there is related
data in BOATTOURL, correct?

> Clng(Request.QueryString("class_ID"))'"', CONN, 2, 3
>
> (this would normally be on one continuous line).
>
> It's a numeric value being passed from a previous page.
>
> As you can tell, I'm not too experienced with .asp OR SQL.
>
> Hope this is enough info and thanks to anyone who would care to take
> the time to look at it.


Here is the most secure way to do this, as well as the easiest.

dim sql, arParms, cmd
sql = "SELECT URL.TITLE, URL.ID, URL.URL from URL " & _
" INNER JOIN BOATTOURL ON URL.ID = URL_ID " & _
"WHERE CLASS_ID =?"

arParms = Array(Clng(Request.QueryString("class_ID")))
set cmd=createobject("adodb.command")
cmd.commandtext=sql
cmd.commandtype=1 'adcmdtext
set cmd.activeconnection = conn
set Recset = cmd.execute(,arParms)


--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


 
Reply With Quote
 
 
 
 
Randy
Guest
Posts: n/a
 
      01-14-2008

"Bob Barrows [MVP]" <> wrote in message
news:...
> Randy wrote:
>> For the life of me, I can't figure out how to correctly punctuate
>> the end of this statement!
>> .ASP classic. Access 2000 database (I'm stuck with this for the time
>> being)
>> When I in an actual value (2052 in this case) as follows:
>>
>> Recset.Open "SELECT URL.TITLE, URL.ID, URL.URL from URL, BOATTOURL
>> WHERE URL.ID = 2052", CONN, 2, 3

>
> ??? Is there no link between URL and BOATTOURL? You're getting a cartesian
> join here. Is that really what is intended? Actually, why does BOATTOURL
> even appear in this sql statement? You're not retrieving any information
> from it ...
>

BOATTOURL contains the link between the form and BOAT. But many thanks for
your help. Let me change things around and try to do it the way you have
suggested, which is undoubtedly better. I'll let you know if I can get it
to work.
>>
>> It works fine and finds all appropriate records.
>>
>> I just can't figure out how to put the request.querystring in there as
>> below. I've put in every comination of single, double, triple quotes
>> I can think of and just won't work.
>>
>> Recset.Open "SELECT URL.TITLE, URL.ID, URL.URL from URL, BOATTOURL
>> WHERE URL.ID = URL_ID AND CLASS_ID =

>
> Is URL_ID in BOATTOURL? if so, the correct syntax to use is JOIN, or more
> explicitly, INNER JOIN. See below.
>
> So the idea is to only retrieve information from URL if there is related
> data in BOATTOURL, correct?
>
>> Clng(Request.QueryString("class_ID"))'"', CONN, 2, 3
>>
>> (this would normally be on one continuous line).
>>
>> It's a numeric value being passed from a previous page.
>>
>> As you can tell, I'm not too experienced with .asp OR SQL.
>>
>> Hope this is enough info and thanks to anyone who would care to take
>> the time to look at it.

>
> Here is the most secure way to do this, as well as the easiest.
>
> dim sql, arParms, cmd
> sql = "SELECT URL.TITLE, URL.ID, URL.URL from URL " & _
> " INNER JOIN BOATTOURL ON URL.ID = URL_ID " & _
> "WHERE CLASS_ID =?"
>
> arParms = Array(Clng(Request.QueryString("class_ID")))
> set cmd=createobject("adodb.command")
> cmd.commandtext=sql
> cmd.commandtype=1 'adcmdtext
> set cmd.activeconnection = conn
> set Recset = cmd.execute(,arParms)
>
>
> --
> Microsoft MVP - ASP/ASP.NET
> Please reply to the newsgroup. This email account is my spam trap so I
> don't check it very often. If you must reply off-line, then remove the
> "NO SPAM"
>

Randy


 
Reply With Quote
 
Randy
Guest
Posts: n/a
 
      01-16-2008

"Randy" <*> wrote in message
news:478b776b$0$11610$...
>
> "Bob Barrows [MVP]" <> wrote in message
> news:...
>> Randy wrote:
>>> For the life of me, I can't figure out how to correctly punctuate
>>> the end of this statement!
>>> .ASP classic. Access 2000 database (I'm stuck with this for the time
>>> being)
>>> When I in an actual value (2052 in this case) as follows:
>>>
>>> Recset.Open "SELECT URL.TITLE, URL.ID, URL.URL from URL, BOATTOURL
>>> WHERE URL.ID = 2052", CONN, 2, 3

>>
>> ??? Is there no link between URL and BOATTOURL? You're getting a
>> cartesian join here. Is that really what is intended? Actually, why does
>> BOATTOURL even appear in this sql statement? You're not retrieving any
>> information from it ...
>>

> BOATTOURL contains the link between the form and BOAT. But many thanks
> for your help. Let me change things around and try to do it the way you
> have suggested, which is undoubtedly better. I'll let you know if I can
> get it to work.
>>>
>>> It works fine and finds all appropriate records.
>>>
>>> I just can't figure out how to put the request.querystring in there as
>>> below. I've put in every comination of single, double, triple quotes
>>> I can think of and just won't work.
>>>
>>> Recset.Open "SELECT URL.TITLE, URL.ID, URL.URL from URL, BOATTOURL
>>> WHERE URL.ID = URL_ID AND CLASS_ID =

>>
>> Is URL_ID in BOATTOURL? if so, the correct syntax to use is JOIN, or more
>> explicitly, INNER JOIN. See below.
>>
>> So the idea is to only retrieve information from URL if there is related
>> data in BOATTOURL, correct?
>>
>>> Clng(Request.QueryString("class_ID"))'"', CONN, 2, 3
>>>
>>> (this would normally be on one continuous line).
>>>
>>> It's a numeric value being passed from a previous page.
>>>
>>> As you can tell, I'm not too experienced with .asp OR SQL.
>>>
>>> Hope this is enough info and thanks to anyone who would care to take
>>> the time to look at it.

>>
>> Here is the most secure way to do this, as well as the easiest.
>>
>> dim sql, arParms, cmd
>> sql = "SELECT URL.TITLE, URL.ID, URL.URL from URL " & _
>> " INNER JOIN BOATTOURL ON URL.ID = URL_ID " & _
>> "WHERE CLASS_ID =?"
>>
>> arParms = Array(Clng(Request.QueryString("class_ID")))
>> set cmd=createobject("adodb.command")
>> cmd.commandtext=sql
>> cmd.commandtype=1 'adcmdtext
>> set cmd.activeconnection = conn
>> set Recset = cmd.execute(,arParms)
>>
>>
>> --
>> Microsoft MVP - ASP/ASP.NET
>> Please reply to the newsgroup. This email account is my spam trap so I
>> don't check it very often. If you must reply off-line,

I solved the problem. (Thanks again.) I did have difficulty with the method
you suggested with the parameters, placeholder '?' etc.
Is there a complete sample somewhere that I can download, which would
include outputing the items in the array, db path etc. I like to able to
figure out these things on my own as much as possible, and only use a forum
such as this to ask specific questions should I have any.

Cheers
Randy Browning


 
Reply With Quote
 
Bob Barrows [MVP]
Guest
Posts: n/a
 
      01-16-2008
Randy wrote:

> I solved the problem. (Thanks again.) I did have difficulty with the
> method you suggested with the parameters, placeholder '?' etc.


What problem? Error message?

> Is there a complete sample somewhere that I can download,


The sample included in the post is as complete as any I've got. This is
the message I usually refer to:
http://groups-beta.google.com/group/...e36562fee7804e

I use stored procedures for the most part.
http://www.google.com/groups?hl=en&l...TNGP12.phx.gbl

http://groups.google.com/groups?hl=e...tngp13.phx.gbl


> which would
> include outputing the items in the array,


? What array?

> db path etc.


Huh?

> I like to
> able to figure out these things on my own as much as possible, and
> only use a forum such as this to ask specific questions should I have
> any.
>
> Cheers
> Randy Browning


--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.


 
Reply With Quote
 
 
 
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
sql timeout from web application problem (works good in sql server dave ASP .Net 2 12-04-2008 02:42 PM
SQL Reference, SQL Queries, SQL help ecoolone ASP .Net 0 01-03-2008 10:58 AM
MS Access SQL > ASP SQL problem.... david@scene-double.co.uk ASP General 10 01-06-2005 12:23 PM
String.replaceAll(String regex, String replacement) question Mladen Adamovic Java 3 12-05-2003 04:20 PM
Re: String.replaceAll(String regex, String replacement) question Mladen Adamovic Java 0 12-04-2003 04:40 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57