473,624 Members | 2,612 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 4714
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
2413
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 hard coded address. When I actually input two addresses, it sends to both. The partial code reads: Set objMail = CreateObject("CDONTS.NewMail") objMail.From= request.form("youremail") 'Specify sender's address...
30
27011
by: priya | last post by:
Hi How to concatenate two integer Values. Example Program : #include "Port.h" #include "BinaryConversion.h" # include "iostream.h"
5
23041
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 day to day, I need to be able to dynamically generate a batch file to concatenate these files. So far, I have looked at using FileSearch.FindFiles.Count to determine the number of files so that I can loop through the files that exist in a...
3
4697
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 - checkbox5. As I loop through my integers i - 5, I want to check my checkboxes, checkbox0- checkbox5. for (int i = 0; i < 5; i++)
5
2801
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 only one word. I try to concatenate each word read into a string variable, separated by a delimiter character. Even though I am able to read the words from the file correctly, I am not able to correctly concatenate the string. I was expecting the...
4
5036
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 matching records here is the cursor loop. I'm not a fan of cursors but also didn't see another way of achieving this. declare @ptr1 varbinary(16) declare @Ptr2 varbinary(16) declare @profileid int declare @x int
13
21817
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 will concatenate the value of ABC to MYSTR . I need this at compile time.
10
7435
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 able to produce a query that gives me two fields, Part_Number and Product_Type. Below you can see some sample data: Part_Number Product_Type 10MC35231 XYZ1A
1
3368
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 "Filename" is filled with a valid value. So how do I otherwise concatenate two parts? Tony
0
8179
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8685
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8490
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7174
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6112
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5570
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2612
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 we have to send another system
1
1796
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1489
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.