Search code examples
sqlvbastring-concatenation

SQL concatenation inside a vbscript


I have a problem with a SQL concatenation used in VB script.

I'm trying to contatenate a variable inside a SQL request but whatever the concatenation method i use, it fails !

Here is my code

dim nbr3Eu as integer = 6
dim waa2Eu as string

waa2Eu = "" _
& "SELECT riblib" _
& "      ," & nbr3Eu _
& "  FROM PCH" _
& "  WHERE RibPaysNuf <> 'NufSocPaysMU'" _
& "    AND PchID in " & XPchID _
& "  GROUP BY DevCode"

I've tried it with the PLUS sign concatenation but i still have the same result

dim nbr3Eu as integer = 6
dim waa2Eu as string

waa2Eu = "" _
+ "SELECT riblib" _
+ "      ," + nbr3Eu _
+ "  FROM PCH" _
+ "  WHERE RibPaysNuf <> 'NufSocPaysMU'" _
+ "    AND PchID in " + XPchID _
+ "  GROUP BY DevCode"

Need help, THANKS


Solution

  • You must concatenate String, try replacing & nbr3Eu by & CStr(nbr3Eu)