 |
| Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Classic ASP Databases 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
|
|
|
|

June 11th, 2004, 04:09 AM
|
|
Authorized User
|
|
Join Date: Feb 2004
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Can i use asp within sql statements
how can i use asp statements within sql is it possible if yes pls
tell me write some examples pls
:D
|
|

June 11th, 2004, 04:43 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
Well, it depends. If you construct your SQL statement in an ASP page, yes you can:
Code:
Dim SQL
SQL = "SELECT Col1, Col2 FROM MyTable WHERE ID = " & MyASPVariable
This will create a query that uses MyASPVariable in the WHERE clause of your SQL statement.
If you're using Stored Procedures, you can also pass ASP variables to those procedures as input parameters.
If you mean you can do something like this in a Stored Procedure
Code:
CREATE Procedure MyProc
AS
SELECT Col1, Col2, FROM MyTable WHERE ID = <%=MyASPVar%>
then the answer is no: you cannot do that.
Is this what you're after?
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
|

June 11th, 2004, 05:12 AM
|
|
Authorized User
|
|
Join Date: Feb 2004
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
it means we could not use asp tags within sql
is it illegile ? update tblRings set name='"&ringname&"',[desc]='"&desc&"', "<% if Request("s1")= "on" then size1="5.5" end if "
%> where item_id = " &Request("item_id")
pls tel me
or can u tell me other method to do that
|
|

June 11th, 2004, 05:18 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Did you read my post? I believe the answer is in there.
Yes, you can, if you construct the SQL in the ASP page. No, you can't if you're trying to use <%= %> syntax inside a stored procedure.
Where are you using this:
update tblRings set name='"&ringname&"',[desc]='"&desc&"', "<% if Request("s1")= "on" then size1="5.5" end if "
%> where item_id = " &Request("item_id")
In an ASP page? If so, you shouldn't use <% %> but simply concatenate your string, like you do with the desc variable. If you're trying to create a dynamic SQL statement, try this:
What is the size thingy supposed to do? If I were you, I'd stay far away from words that sound like reserved words, like desc and size.
Cheers,
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
|

June 11th, 2004, 06:02 AM
|
|
Authorized User
|
|
Join Date: Feb 2004
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
i use size1,size2... not size i think they are different from size reserve word 2nd i want to use this
strsql="update tblRings set name='"&ringname&"',[desc]='"&desc&"', "<% if Request("s1")= "on" then size1="5.5" end if "
%> where item_id = " &Request("item_id")
and after this
objRS.open strsql,conn
is it ok or not
dear imar i m trying 2 learn asp and i only read beginning asp 3.0 now so i m lammer in asp pls dont mind my foolish questions
|
|

June 11th, 2004, 06:13 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
I assume that strsql="update .... is already within a server side code block, right? In that case, there is no need for <% and %>. Simply concatenate the various parts of your SQL statement:
Code:
strsql = "UPDATE tblRings SET name = '" & ringname & "',[desc]='" & desc
If Request("s1")= "on" Then
strsql = strsql & ", size1 = "5.5"
End If
strsql = strsql & "WHERE item_id = " & Request("item_id")
Does this help?
Don't worry about foolish question. I was always taught there is no such things as a foolish question; just foolish answers ;)
I was just afraid that you didn't look carefully enough at my answer.....
Cheers,
Imar
|
|

June 11th, 2004, 06:25 AM
|
|
Authorized User
|
|
Join Date: Feb 2004
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
no it didnt work
|
|

June 11th, 2004, 07:23 AM
|
|
Friend of Wrox
|
|
Join Date: May 2004
Posts: 642
Thanks: 0
Thanked 43 Times in 42 Posts
|
|
Try this :
<%
strsql = "UPDATE tblRings SET name = '" & ringname & "',[desc]='" & desc & "' "
If Request("s1")= "on" Then
strsql = strsql & ", size1 = 5.5"
End If
strsql = strsql & "WHERE item_id = " & Request("item_id")
%>
Does this help?
Om Prakash
|
|

June 11th, 2004, 08:57 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Try this instead:
strsql = strsql & ", size1 = 5.5"
Otherwise, please define "did not work". Posting detailed error info and descriptions makes things so much easier.....
Imar
|
|

June 14th, 2004, 12:04 AM
|
|
Authorized User
|
|
Join Date: Feb 2004
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
ok this is working fine but how can i empty the size1 field other condition
|
|
 |