Based on a recent email exchange with a colleague, it occurred to me that this might be handy to post as a blog entry.
The question - “Why do you need the added ‘&’ statement in VBScript for variables? “
When you are using variables in select statements, they have to properly resolve into the syntax that VBScript would understand.
To illustrate this example, review the following VBScript:
‘ begin script
strComputer = "GENIUS"
strSQL = "Select foo FROM table WHERE Name = 'strComputer'"
Wscript.Echo strSQL
strSQL = "Select foo FROM table WHERE Name = '" & strComputer & "'"
Wscript.Echo strSQL
‘ end script
Save it as with a VBS extension, then run it. You should get these results:


Note: If you are using numeric variables, you would not include the quotes.