473,396 Members | 1,866 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Passing an variable to within an sql statement

I am still learning asp and sql.
I am having trouble with passing a variable to within an sql statement.
I am sure it is something simple like misuse of quotes.

Since it may help if i say what i am trying to generally accomplish
here.
This is an access database for products and customers. We have a
counter for each product (such as ProdCountLB, ProdCountSH, etc for the
field names in a table called ProdCount).
This worked fine when i explicitly addressed them. Now that i have made
the explicit names of the field into a variable (ProdCountVar), I need
to use it in the SQL statment.
It fails at this point an di have tried several variations of quotes
and ampersands to no avail.

Any suggestions? Thank you
Here is a snippet of the code.
(pCode is variabel that gives teh vatule of LB, SH..etc and is combined
with the phrase ProdCount to form ProdCountVar)

Dim OBJdbConnection, ProdCountVar

ProdCountVar=ProdCount&pCode

Set OBJdbConnection = Server.CreateObject("ADODB.Connection")
OBJdbConnection.Open "DSN=tbe"

CountQuery = "SELECT * FROM ProdCount "
Set CQS = OBJdbConnection.Execute(CountQuery)
ProdCounts = CQS(&ProdCountVar&)
NewProdCount = ProdCounts+1
CountBack = "UPDATE ProdCount SET
"&ProdCountVar&"='"&NewProdCount&"' WHERE CountIdent=1"

Apr 24 '06 #1
1 1658

I.*************@gmail.com wrote:
I am still learning asp and sql.
I am having trouble with passing a variable to within an sql statement.
I am sure it is something simple like misuse of quotes.

Since it may help if i say what i am trying to generally accomplish
here.
This is an access database for products and customers. We have a
counter for each product (such as ProdCountLB, ProdCountSH, etc for the
field names in a table called ProdCount).
This worked fine when i explicitly addressed them. Now that i have made
the explicit names of the field into a variable (ProdCountVar), I need
to use it in the SQL statment.
It fails at this point an di have tried several variations of quotes
and ampersands to no avail.

Any suggestions? Thank you
Here is a snippet of the code.
(pCode is variabel that gives teh vatule of LB, SH..etc and is combined
with the phrase ProdCount to form ProdCountVar)

Dim OBJdbConnection, ProdCountVar

ProdCountVar=ProdCount&pCode
If ProdCount is a phrase (string) it should be in quotes

Set OBJdbConnection = Server.CreateObject("ADODB.Connection")
OBJdbConnection.Open "DSN=tbe"

CountQuery = "SELECT * FROM ProdCount "
You don't need to select all columns at all, just the one you one to
update, which is assigned to the variable ProdCountVar. You have not
specified which row you want to return, so all rows will be returned.
When you reference the record in the line after next to increment the
value by 1, it will only work with the first record returned - every
time.
Set CQS = OBJdbConnection.Execute(CountQuery)
ProdCounts = CQS(&ProdCountVar&)
You really need to leave spaces around your ampersands. Not essential,
but it makes it so much easier to read.
NewProdCount = ProdCounts+1
CountBack = "UPDATE ProdCount SET
"&ProdCountVar&"='"&NewProdCount&"' WHERE CountIdent=1"


NewProdCount is a number, but you have delimited it as a string.
Try this:

<%

ProdCountVar = "ProdCount" & pCode

Set OBJdbConnection = Server.CreateObject("ADODB.Connection")
OBJdbConnection.Open "DSN=tbe"

CountQuery = "SELECT " & ProdCountVar & " FROM ProdCount WHERE
CountIdent=1"
Set CQS = OBJdbConnection.Execute(CountQuery)
NewProdCount = CQS(" & ProdCountVar & ")+1
CountBack = "UPDATE ProdCount SET " & ProdCountVar & " = " &
NewProdCount & " WHERE CountIdent=1"

%>

--
Mike Brind

Apr 25 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
6
by: veganeater | last post by:
Hi Everyone, I was wondering if there was a way to pass a variable to a popup window. The purpose is make it so when a user clicks on a specific region/link of the glossary page, a popup opens...
4
by: hello smith | last post by:
I have a lot of functions that add values to an array. They alos update a global variable of type int. Currently, I use a global variable to hold this array. All functions access this array...
2
by: jbatty | last post by:
I am trying to display an image on my page by using "img src= hyperlink". the hyperlink is stored in a c# variable. but i seem to have the syntax mixed up. This passing the image directly works...
0
by: CES | last post by:
All, I was wondering is their a way of passing a variable into an eval() statement? I've created a custom eval() dll to use with my VB.net code. Every thing works fine until I try to pass a...
2
by: Jerry Spence1 | last post by:
I have seen the following example of passing data to a thread: Class ThreadData Public Id As Integer Public Msg As String Public Done As Boolean ' The entry point for the ...
6
by: MSDNAndi | last post by:
Hi, I get the following warning: "Possibly incorrect assignment to local 'oLockObject' which is the argument to a using or lock statement. The Dispose call or unlocking will happen on the...
11
by: kennthompson | last post by:
Trouble passing mysql table name in php. If I use an existing table name already defined everything works fine as the following script illustrates. <?php function fms_get_info() { $result =...
0
by: Mark C. Stock | last post by:
"Mark C. Stock" <mcstockX@Xenquery .comwrote in message news:... | | "Berend" <Berend.Brinkhuis@evatone.comwrote in message | news:bdd9ac20.0401271301.22cdb65e@posting.google.com... | | I am...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.