Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Comibne two Queries to get results
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Yak Posting Veteran

89 Posts

Posted - 10/03/2012 :  14:44:35  Show Profile  Reply with Quote

I am using this query

SELECT InvDate, Location, Inv+obs as Total
FROM InvInfo where (InvDate >= '8/1/2012')
and (InvDate <= '8/31/2012') Group by InvDate ,Location
) d
SUM (Total)
FOR Location in ( [Dallas', [Atlanta], [Houston], [Raleigh], [Chicago] )
) p

By using above query getting this results

Date Dallas Atlanta Houston Raleigh Chicago
1 100 50 80 75 120
2 80 60 77 82 110

But In above results i want one more extra column(OBS) , thats gives my Actual results as shown below

Here is the Expecting Results

Date Dallas Atlanta Houston Raleigh Chicago OBS
1 100 50 80 75 120 20
2 80 60 77 82 110 18

This extra columns will get by below query

select sum(OBS) as OBS from InvInfo where (InvDate >= '8/1/2012')
and (InvDate <= '8/31/2012') Group by InvDate

So how to combine these two queries to get Actual results as shown above.

Please anyone Can help me on this?




Very Important crosS Applying yaK Herder

52326 Posts

Posted - 10/03/2012 :  15:28:07  Show Profile  Reply with Quote

SQL Server MVP

Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000