Wrox Programmer Forums
|
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
 
Old July 3rd, 2003, 10:48 PM
Authorized User
 
Join Date: Jun 2003
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to tp194
Default Quoting variables in SQL statements

Can someone please explain to a newbie when I need to use quotes with variables in my sql statements?

I've seen code with " & variable & " like the example below...what does this mean?

Thanks

"INSERT INTO linkToCategory(ein, categoryId) " & _
"VALUES (" & EIN & ", " & selectedGroup &")"
 
Old July 4th, 2003, 03:41 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

You always need to use this " & variable & " syntax. This is because you want to embed the value of the variable into the SQL statement. If you don't use this syntax, you will be embedding the name of the variable instead.

Using your SQL statement as an example, suppose you have:
EIN = 1
selectedGroup = 2

then if you do:
"INSERT INTO linkToCategory(ein, categoryId) " & _
"VALUES (" & EIN & ", " & selectedGroup &")"

that gives you this SQL statement:
Code:
INSERT INTO linkToCategory(ein, categoryId) VALUES (1, 2)
which is what you want.

If you don't use the " & variable & " syntax then you have:
"INSERT INTO linkToCategory(ein, categoryId) " & _
"VALUES (EIN, selectedGroup)"

which gives this SQL statement:
Code:
INSERT INTO linkToCategory(ein, categoryId) VALUES (EIN, selectedGroup)
and you don't want that because the database will assume that EIN and selectedGroup are the actual values you're trying to insert. The database will not know that EIN and selectedGroup are variables in your code that contain the values you want to insert.

hth
Phil





Similar Threads
Thread Thread Starter Forum Replies Last Post
Can i use asp within sql statements knight Classic ASP Databases 43 May 24th, 2007 09:32 AM
CASE Statements in T-SQL atcs2152 SQL Server 2000 3 April 28th, 2006 10:53 AM
Global Variables and SQL statements in DTS gmctrek SQL Server DTS 0 October 7th, 2005 03:08 PM
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





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