[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

SQL Union Count SUM quey

Posted on 2008-02-05
7
Medium Priority
?
1,304 Views
Last Modified: 2008-12-01
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
0
Comment
Question by:R8VI
  • 3
  • 2
  • 2
7 Comments
 
LVL 18

Accepted Solution

by:
Jinesh Kamdar earned 600 total points
ID: 20823631
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
 
LVL 15

Assisted Solution

by:Faiga Diegel
Faiga Diegel earned 400 total points
ID: 20823652

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
 

Author Comment

by:R8VI
ID: 20823748
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 new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
LVL 15

Expert Comment

by:Faiga Diegel
ID: 20823797
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
 
LVL 18

Expert Comment

by:Jinesh Kamdar
ID: 20823806
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
 

Author Comment

by:R8VI
ID: 20823980
Thank You very much works now much appreciated
0
 
LVL 18

Expert Comment

by:Jinesh Kamdar
ID: 20824005
Glad to be of help :)
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
If you try to migrate from Elastix to Issabel, you will face a lot of issues. These problems are inevitable but fortunately, you can fix them. In the guide below, I will explain how I performed the migration while keeping all data and successfully t…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

612 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question