SQL Union Count SUM quey

I have the following query it return two rows with values of 300 and 12 what i need to do is get the total of both Rows and display one answer.
Any help is much appreciated.

SELECT Count (SId) As Total From R Where SID='HL'
UNION
SELECT Count(1) As Total FROM Archive where Closed IS NULL
R8VIAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jinesh KamdarCommented:
SELECT SUM(total) FROM
(SELECT Count (SId) As Total From R Where SID='HL'
UNION
SELECT Count(1) As Total FROM Archive where Closed IS NULL)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Faiga DiegelSr Database EngineerCommented:

declare @Total1 as int
declare @Total2 as int

SELECT @Total1 = Count (SId) From R Where SID='HL'
SELECT @Total2 = Count(1) FROM Archive where Closed IS NULL

select @Total1 + @Total2

Does that meet your need?
0
R8VIAuthor Commented:
Hi guys thaanks.
I am assuming either should work.
However the first solution by jinesh_kamdar says invalid syntax ')'
I dont know why
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

Faiga DiegelSr Database EngineerCommented:
jinesh_kamdar's solution is more efficient, just add 'as A'

SELECT SUM(total) FROM
(SELECT Count (SId) As Total From R Where SID='HL'
UNION
SELECT Count(1) As Total FROM Archive where Closed IS NULL) as A
0
Jinesh KamdarCommented:
I always mess up with the aliases. faiga16 is right. Just add the alias and you should be good.

SELECT SUM(A.total) FROM
(SELECT Count (SId) As Total From R Where SID='HL'
UNION
SELECT Count(1) As Total FROM Archive where Closed IS NULL) as A
0
R8VIAuthor Commented:
Thank You very much works now much appreciated
0
Jinesh KamdarCommented:
Glad to be of help :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2005

From novice to tech pro — start learning today.