473,499 Members | 1,579 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trying to concatenate variable into SQL Statement

5 New Member
I have the following working SQL in my Function;

strSQL2 = "SELECT Merch.Loc, Merch.Hub, Merch.Item, Merch.[Total Qty], Merch.[Avg Cost]" & _
"into TblTemp2 " & _
"FROM [Merch]" & _
"WHERE (((Merch.Item)= '1387' ));"


I want to replace 1387 in the last line with a variable called itm, the string below doesn't work, despite trying about 1000 syntax permutations!

strSQL2 = "SELECT Merch.Loc, Merch.Hub, Merch.Item, Merch.[Total Qty], Merch.[Avg Cost]" & _
"into TblTemp2 " & _
"FROM [Merch] WHERE (Merch.Item)" & " = " & itm & ";"

What did I screw up?

Thanks

Don
Jan 28 '09 #1
3 4704
MikeTheBike
639 Recognized Expert Contributor
Hi

Try this


strSQL2 = "SELECT Merch.Loc, Merch.Hub, Merch.Item, Merch.[Total Qty], Merch.[Avg Cost]" & _
"into TblTemp2 " & _
"FROM [Merch]" & _
"WHERE (((Merch.Item)= '" & itm & "' ));"


ie. just replace 1387 with " & itm & "

but leave to 2 apostrophies in place !!

HTH

MTB
Jan 29 '09 #2
HTDon
5 New Member
Worked like a charm, I knew there was one comonation of ' " ] } and )s that I missed!
Jan 29 '09 #3
otacons
1 New Member
YEP, that was it!

string variable in sql statement visual basic 6

it works super, thanks a lot! =)

My problem was that I wrote: '& itm & ', cause my string variable already had " ", but still you have to write it on the sql statement.

item = "abcde"

'" & itm & "'

@MikeTheBike
Nov 2 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2410
by: Len Burman | last post by:
I have some code in a form which inputs a friends email address and when you submit it sends the message to the person at the address. I want to be able to email to the variable name and also a...
30
26970
by: priya | last post by:
Hi How to concatenate two integer Values. Example Program : #include "Port.h" #include "BinaryConversion.h" # include "iostream.h"
5
23031
by: gwarning! | last post by:
Goal: Have multiple text files, each of various lengths, be concatenated together into one final consolidated text file. Problem: Since the names of the files to be concatenated can change from...
3
4689
by: tirrell payton | last post by:
Hello all, I have a question about the concatenation operator in C#. For example, I want to concatenate an integer variable to a control. I have an integer, i. I have checkboxes, checkbox0 -...
5
2791
by: Generic Usenet Account | last post by:
I have been to recreate a problem that I am having with strings with the trivial code snippet given below. In the trivial code example, I am reading five lines from a data file, each line having...
4
5028
by: Dan | last post by:
Hi all, I am creating a search table where the keywords field is made up of several text fields and this is causing me some problems. I can concatentate the text ok but i can't seem to concatenate...
13
21779
by: sinbad | last post by:
hi, how to concatenate a "hash defined" constant value to another "hash defined" constant string. For example #define ABC 100 #define MYSTR "The value of ABC is" Now i need a string that...
10
7416
by: Aaron Hoffman | last post by:
Hello, I'm hoping someone might be able to offer some guidance to my problem. I have one query in MS Access which consists of 2 tables joined by a SEQUENCE_ID. By joining the two tables I am...
1
3358
by: Tony Bansten | last post by:
Assume I want to concatenate a literal text value and a variable value for a function parameter then the following does NOT work: objWorkbook.SaveAs("D:\work\v1_" + Filename) The variable...
0
7007
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
7220
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...
1
6893
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
7386
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...
0
5468
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4918
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4599
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
664
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.