473,395 Members | 1,653 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,395 software developers and data experts.

variables in strings

Hi I'm having trouble with variables in an INSERT INTO string that I'm
executing in A97 to SQL Server 2k tables.
I can get the SQL command to work using values such as :
strSQL2 = "INSERT INTO tblEmployee "
strSQL2 = strSQL2 & "SELECT tblProducts.CostCentre, tblProducts.Class,
tblProducts.ProductGroup, 9016255 AS EmployID, tblProducts.Description,
tblProducts.Division, tblProducts.BusinessUnit, tblProducts.Category,
tblProducts.EmplDefault AS Allocation, tblProducts.Vis, Now() AS Modified,
CurrentLogin() AS ModifiedBy"
strSQL2 = strSQL2 & " FROM tblProducts"
strSQL2 = strSQL2 & " WHERE (((tblProducts.CostCentre)= 221) AND
((tblProducts.Vis)=True));"

But as soon as I replace 916255 with " & rst!EmployeeNumber & " it stops
working. EmployeeNumber is a field in a recordset and is active when this
query is executed.
Same with the cost centre 221
I can only guess I'm messing up the number of quotes around the variable. By
trial and error some appear to work but the data just isnt being inserted.
Am I doing something else wrong?.
TIA
Nov 13 '05 #1
2 1931
"Damon Grieves" <da****@vfeNOSPAMmail.net> wrote in message
news:42**********************@news.optusnet.com.au ...
Hi I'm having trouble with variables in an INSERT INTO string that I'm
executing in A97 to SQL Server 2k tables.
I can get the SQL command to work using values such as :
strSQL2 = "INSERT INTO tblEmployee "
strSQL2 = strSQL2 & "SELECT tblProducts.CostCentre, tblProducts.Class,
tblProducts.ProductGroup, 9016255 AS EmployID, tblProducts.Description,
tblProducts.Division, tblProducts.BusinessUnit, tblProducts.Category,
tblProducts.EmplDefault AS Allocation, tblProducts.Vis, Now() AS Modified,
CurrentLogin() AS ModifiedBy"
strSQL2 = strSQL2 & " FROM tblProducts"
strSQL2 = strSQL2 & " WHERE (((tblProducts.CostCentre)= 221) AND
((tblProducts.Vis)=True));"

But as soon as I replace 916255 with " & rst!EmployeeNumber & " it stops
working. EmployeeNumber is a field in a recordset and is active when this
query is executed.
Same with the cost centre 221
I can only guess I'm messing up the number of quotes around the variable.
By
trial and error some appear to work but the data just isnt being inserted.
Am I doing something else wrong?.
TIA


I would guess it is to do with the quotes. You need a consistent way to
handle them, but you depending on how you are inserting rows into SQL Server
you will need either single (pass-through queries, etc) or double (odbc)
quotes. Assuming it is odbc just use the function below to add quotes, but
be careful with null values - just go slowly

e.g.
If EmployeeNumber is text (not a real number)
strTemp = Trim(Nz(rst!EmployeeNumber,""))
If Len(strTemp)>0 Then
strSQL=strSQL & AddDoubleQuotes(strTemp)
End if
....
....

Public Function AddDoubleQuotes(strValue) As String

Dim strReturn As String

strReturn = Replace(strValue, """", """""")
strReturn = """" & strReturn & """"

AddDoubleQuotes = strReturn

End Function


Nov 13 '05 #2
I don't deal with SQL Server, but in Access when I have a variable in a
SQL statement that's a string, I do this (using a WHERE clause just to
illustrate):

...."WHERE T.Field = " & Chr(34) & value & Chr(34) & .....

(The Chr(34) function call returns a quotation mark.)

Although this approach yields longer SQL strings, I never have any more
quotes-related issues (that is, if I remember to put them in there!)
From you post above, however, I get the idea that the employee ID field

is a number??? If it really is a string, this could be the issue.

Johnny

Nov 13 '05 #3

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

Similar topics

1
by: Rolf Kemper | last post by:
Dear All, does have anybody have an idea how to add to number strings in xslt ? My strings are in variables eg. '1A2' , '00F' which should sum up to '1B1'. I may prefix the variables with...
3
by: Anthony Robinson | last post by:
We're encountering an issue with working with CLOB's. We're doing a basic insert into a table that has a CLOB column. Sometimes the CLOB is fairly tame in size (10k-15k), and once in a while...
6
by: RFS666 | last post by:
Hello, After I posted yesterday "using C# class in jscript", I have a new problem: I have a C# class - DBResult - that contains (and other variables) a string array (and other variables), that...
5
by: Just Me | last post by:
Using streams how do I write and then read a set of variables? For example, suppose I want to write into a text file: string1,string2,string3 Then read them later. Suppose I want to write...
6
by: calcop | last post by:
Hello everyone, I hope I can write this question clearly. Anyway, it is about global variables. I have several files in my C++ project. One of which is main.cpp. This file comtains my main()...
9
by: Schraalhans Keukenmeester | last post by:
I am stomped with the following problem: I have a script start.php and a second script proceed.php Relevant (and working) sections of the code: start.php <?PHP start_session();
3
by: Gal Diskin | last post by:
Following a discussion with an associate at work about various ways to build strings from variables in python, I'd like to hear your opinions and preferred methods. The methods we discussed are:...
20
by: tshad | last post by:
Using VS 2003, I am trying to take a class that I created to create new variable types to handle nulls and track changes to standard variable types. This is for use with database variables. This...
18
by: Bruce | last post by:
When I do this: <input id="someName" type="text"> <script type="text/javascript"> alert(someName.nodeName); </script> Both IE6 and Firefox alert("INPUT"). Why isn't "someName" undefined?
6
KevinADC
by: KevinADC | last post by:
This snippet of code provides several examples of programming techniques that can be applied to most programs. using hashes to create unique results static variable recursive function...
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: 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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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.