Implementing a variable with quotes in SQL | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 6

Implementing a variable with quotes in SQL

so iam trying to make a sub to get data from an excel sheet and its working good but then i want to set 3 labels when i call a sub and that sub takes 1 parameter as State and iam trying to do "SELECT DC FROM [Data$] WHERE State=""" & State & """" to make a string eg. SELECT DC FROM [Data$] WHERE State="New York" but it doesnt seem to work well as it gives me a datatable of nothing

3rd Jun 2017, 12:25 AM
StealthBlade
StealthBlade - avatar
7 Answers
+ 3
Shouldn't you include two double qoutes in new york like ""NEW YORK"" instead of "NEW YORK" ?
3rd Jun 2017, 12:28 PM
🇺🇸 Anatoli🇧🇪🇪🇺 ,
🇺🇸 Anatoli🇧🇪🇪🇺 , - avatar
+ 1
I thought that you were supposed to use a single quotes outside the double quotes instead of two sets of double quotes. This would be normal for SQL but it may be different in your situation
3rd Jun 2017, 8:48 PM
Ram91
Ram91 - avatar
+ 1
its because iam using vb.net for it so if i use ' it gets commented and it looks like when SQL connected to vb.net it can use " or something like that
3rd Jun 2017, 10:52 PM
StealthBlade
StealthBlade - avatar
+ 1
@Iwan, can you send your message in English please? Russian is not much available here in SoloLearn. Perhaps you try a translation from Google... By the way, welcome here at SoloLearn...
9th Jun 2017, 8:24 AM
🇺🇸 Anatoli🇧🇪🇪🇺 ,
🇺🇸 Anatoli🇧🇪🇪🇺 , - avatar
0
the rest of the code has the final output of the SQL statement like that and its working fine
3rd Jun 2017, 1:42 PM
StealthBlade
StealthBlade - avatar
0
I am not sure, but it looks like you are missing a set of double quotes...you only have 3 double quotes after State = and you have 4 double quotes at the end.
3rd Jun 2017, 1:48 PM
Ram91
Ram91 - avatar
0
notice the double quote at the start of the code @Ricky the reason iam having 3 double quotes before is i searched how to put a double quote in a string and i found out that to do so you need 2 empty strings next to each other which means 4 double quotes but if the quote after a string you just put 2 double quotes after the closing of the string behind it
3rd Jun 2017, 1:53 PM
StealthBlade
StealthBlade - avatar