Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP 3 Classic ASP Active Server Pages 3.0 > Classic ASP Databases
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 11th, 2004, 04:09 AM
Authorized User
 
Join Date: Feb 2004
Location: Karachi, , Pakistan.
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to knight
Default 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

Reply With Quote
  #2 (permalink)  
Old June 11th, 2004, 04:43 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

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.
Reply With Quote
  #3 (permalink)  
Old June 11th, 2004, 05:12 AM
Authorized User
 
Join Date: Feb 2004
Location: Karachi, , Pakistan.
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to knight
Default

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

Reply With Quote
  #4 (permalink)  
Old June 11th, 2004, 05:18 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

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.
Reply With Quote
  #5 (permalink)  
Old June 11th, 2004, 06:02 AM
Authorized User
 
Join Date: Feb 2004
Location: Karachi, , Pakistan.
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to knight
Default

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





Reply With Quote
  #6 (permalink)  
Old June 11th, 2004, 06:13 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

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
Reply With Quote
  #7 (permalink)  
Old June 11th, 2004, 06:25 AM
Authorized User
 
Join Date: Feb 2004
Location: Karachi, , Pakistan.
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to knight
Default

no it didnt work

Reply With Quote
  #8 (permalink)  
Old June 11th, 2004, 07:23 AM
Friend of Wrox
Points: 2,473, Level: 20
Points: 2,473, Level: 20 Points: 2,473, Level: 20 Points: 2,473, Level: 20
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2004
Location: India
Posts: 642
Thanks: 0
Thanked 43 Times in 42 Posts
Default

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
Reply With Quote
  #9 (permalink)  
Old June 11th, 2004, 08:57 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

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
Reply With Quote
  #10 (permalink)  
Old June 14th, 2004, 12:04 AM
Authorized User
 
Join Date: Feb 2004
Location: Karachi, , Pakistan.
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to knight
Default

ok this is working fine but how can i empty the size1 field other condition

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
parametising sql statements in ASP classic trufla Classic ASP Basics 5 June 18th, 2008 02:38 PM
CASE Statements in T-SQL atcs2152 SQL Server 2000 3 April 28th, 2006 10:53 AM
Sql statements in data adapter Raif ASP.NET 1.0 and 1.1 Basics 1 July 14th, 2004 08:50 AM
SQL Statements marmer Classic ASP Basics 3 November 13th, 2003 01:42 AM
Quoting variables in SQL statements tp194 Classic ASP Databases 1 July 4th, 2003 03:41 AM



All times are GMT -4. The time now is 07:14 AM.


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