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

VB ScriptMicrosoft SQL ServerDatabases

Avatar of undefined
Last Comment
usslindstrom
ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of usslindstrom
usslindstrom
Flag of Japan image

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
Microsoft SQL Server
Microsoft SQL Server

Microsoft SQL Server is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.SQL Server is available in multiple versions, typically identified by release year, and versions are subdivided into editions to distinguish between product functionality. Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning.

171K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo