troubleshooting Question

MS SQL: complex query that has multiple queries in one

Avatar of auldh
auldh asked on
Microsoft SQL Server
16 Comments1 Solution30 ViewsLast Modified:
MSSQL
Have 1 database, need to pose four queries to create a single result. The first query will return "Application" name.
;WITH group1 AS
(
SELECT [CLASS] AS EXTENSION, [CLASSNAME] AS TYPE, [KEYNAME] AS KIND, [KEY]
   FROM SYSTEM WHERE KEYNAME = '#APPLICATION'
)
Second query collects "VBOX" name
, group2 AS
(
SELECT [CLASS] AS EXTENSION, [CLASSNAME] AS TYPE, [KEYNAME] AS KIND, [KEY]
   FROM SYSTEM WHERE KEYNAME = '#VBOX'
)
Third uses the two group to present a result with single row per record.
SELECT * FROM group1
   JOIN group2 on group1.EXTENSION = group2.EXTENSION
      ORDER BY group1.EXTENSION ASC


These work well but my issue is the columns present "numeric" values for the "KEY" columns. So I need to re-query the "SYSTEM" table to find matching data that match the [KEY].numeric result.
EXTENSION   TYPE   KIND   KEY   EXTENSION   TYPE   KIND   KEY
11011121600   VMX   #APPLICATION   AF71B74D301842C   11011121600   VMX   #VBOX   BC56379D-B99C-4058-A563-E0CE3D0C1480
The above is a sample of the result. Want to query the "SYSTEM" table looking for more data regarding each row's final KEY column. Example looking for "BC56379D-B99C-4058-A563-E0CE3D0C1480". The result will be two column with EXTENSION and the result of the forth query.

As there are 186 rows return by the first three linked queries there will 186 row of two columns in the final result.
Any help would be appreciated.
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 16 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 16 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros