Link to home
Start Free TrialLog in
Avatar of usslindstrom
usslindstromFlag for Japan

asked on

SQL Union syntax in VBScript?

Experts, I have the 3 following individual queries that I run from VB against SQL.

I'm trying to figure out how to make them a "UNION SELECT" statement, but can't get the syntax right.

Would somebody know how I could update the 3 individual query strings into a single one? - that way I can do a DISTINCT against the query to drop duplicates.

Thanks for any information you can provide.
objRecordSet.Open "SELECT PrinterName, DriverFileName, DriverTextString, ModelNumber FROM " & SQLTable_PrinterMap_Global, _
            objConnection, adOpenStatic, adLockOptimistic


    objRecordSet.Open "SELECT PrinterName, DriverFileName, DriverTextString, ModelNumber FROM " & SQLTable_PrinterMap_Room & " WHERE RoomNumber = '" & ComputerLocation & "'", _
            objConnection, adOpenStatic, adLockOptimistic


    objRecordSet.Open "SELECT PrinterName, DriverFileName, DriverTextString, ModelNumber FROM " & SQLTable_PrinterMap_Computer & " WHERE ComputerName = '" & ComputerName & "'", _
            objConnection, adOpenStatic, adLockOptimistic

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of usslindstrom

ASKER

That is absolutely perfect!

Thank you very much.  It looks like I almost had the same text in my sql string, but I was missing some quotation marks around items.

Much appreciated!

*On note, I do like you you turned the whole SQL statement into a variable.  Much easier to read.  :o