troubleshooting Question

Combine two sql queries

Avatar of Dan560
Dan560Flag for United Kingdom of Great Britain and Northern Ireland asked on
Microsoft SQL ServerMicrosoft SQL Server 2008SQL
5 Comments1 Solution355 ViewsLast Modified:
Hi I have two SQL queries that work correctly when run on their own.

What I want to do - is have one combined query that returns the sum (4th) field in the second query as an additional column in the first query. the first three columns in each table contain the same data.

First query

Select a.pl_date, a.pl_market, a.pl_code,sum(c.pl_actual)
from pl_actual a, pl_actual c
where a.pl_market=c.pl_market
And a.pl_code=c.pl_code
And c.pl_date >= trim(left(a.pl_date,4))+'.01'
And c.pl_date <= a.pl_date
Group by a.pl_date, a.pl_market, a.pl_code

Second Query

Select a.pl_date, a.pl_market, a.pl_code,sum(b.pl_budget)
from pl_actual a, pl_budget b
where a.pl_market=b.pl_market
And a.pl_code=b.pl_code
And b.pl_date >= trim(left(a.pl_date,4))+'.01'
And b.pl_date <= a.pl_date

Group by a.pl_date, a.pl_market, a.pl_code

Thanks for any assistance
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 5 Comments.
Join the Community
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 5 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