troubleshooting Question

Union Query

Avatar of karinos57
karinos57Flag for Afghanistan asked on
Microsoft SQL Server 2005Microsoft SQL Server 2008SQL
6 Comments4 Solutions413 ViewsLast Modified:
Hi,
How can I use union query or any other method just combine the results from these 3 queries in one output result?  I basically want the output to be like this:

Date       MachineType       Node        AvgAvail_First         AvgAvail_Second                  AvgAvail_Third


here is my qry:
-- 1st Query
select Date, MachineType, Node, Avg(Availability)as AvgAvail_First
from

(select * from openquery(MyLink,
'SELECT convert (varchar, datetime, 101)as Date,
n.MachineType,
r.Availability / 100 AS AvgOfAvailability,
r.Availability,
n.Caption AS Node
FROM G3SQL1.perf.dbo.Nodes n INNER JOIN
G3SQL1.netperfmon.dbo.ResponseTime r ON n.NodeID = r.NodeID
and n.machinetype not like ''Windows%''
and MachineType is not null  
and datediff(dd,[DateTime],getdate()) = 3
order by date asc'))a
group by Date, MachineType, Node
order by date asc



--2nd Query
select Date, MachineType, Node, Avg(Availability)as AvgAvail_Second
from

(select * from openquery(MyLink,
'SELECT convert (varchar, datetime, 101)as Date,
n.MachineType,
r.Availability / 100 AS AvgOfAvailability,
r.Availability,
n.Caption AS Node
FROM G3SQL1.perf.dbo.Nodes n INNER JOIN
G3SQL1.netperfmon.dbo.ResponseTime r ON n.NodeID = r.NodeID
and n.machinetype not like ''Windows%''
and MachineType is not null  
and datediff(dd,[DateTime],getdate()) = 2
order by date asc'))a
group by Date, MachineType, Node
order by date asc


--3rd Query
select Date, MachineType, Node, Avg(Availability)as AvgAvail_Third
from

(select * from openquery(MyLink,
'SELECT convert (varchar, datetime, 101)as Date,
n.MachineType,
r.Availability / 100 AS AvgOfAvailability,
r.Availability,
n.Caption AS Node
FROM G3SQL1.perf.dbo.Nodes n INNER JOIN
G3SQL1.netperfmon.dbo.ResponseTime r ON n.NodeID = r.NodeID
and n.machinetype not like ''Windows%''
and MachineType is not null  
and datediff(dd,[DateTime],getdate()) = 1
order by date asc'))a
group by Date, MachineType, Node
order by date asc

thanks
ASKER CERTIFIED SOLUTION
ralmada

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 4 Answers and 6 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 4 Answers and 6 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