Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
wewe_2090
Starting Member
4 Posts |
Posted - 2014-04-09 : 00:35:20
|
dear all,how to count the total for 2 queries from 2 different tables.query 1:select COUNT (SEGMENT_CODE) AS TOTALROW FROM table1 WHERE SEGMENT_CODE = 'FF' i get the total : 2query 2:select COUNT (SEGMENT_CODE) AS TOTALROW FROM table2 WHERE SEGMENT_CODE = 'FF' i get the total : 3 how to combine 2 query then to get the total 2 + 3 = 5please help.thanks. |
|
stepson
Aged Yak Warrior
545 Posts |
Posted - 2014-04-09 : 01:13:20
|
there are a few ways:select sum(TOTALROW) as TOTALROWFROM( select COUNT (SEGMENT_CODE) AS TOTALROW FROM table1 WHERE SEGMENT_CODE = 'FF' UNION ALL select COUNT (SEGMENT_CODE) AS TOTALROW FROM table2 WHERE SEGMENT_CODE = 'FF')A sabinWeb MCP |
|
|
stepson
Aged Yak Warrior
545 Posts |
Posted - 2014-04-09 : 01:14:48
|
[code]declare @TR1 as int,@TR2 as int select @TR1=COUNT (SEGMENT_CODE) FROM table1 WHERE SEGMENT_CODE = 'FF' select @TR2=COUNT (SEGMENT_CODE) FROM table2 WHERE SEGMENT_CODE = 'FF')A select (@TR1+@TR2) as TOTALROW[/code]sabinWeb MCP |
|
|
wewe_2090
Starting Member
4 Posts |
Posted - 2014-04-09 : 05:51:51
|
quote: Originally posted by stepson there are a few ways:select sum(TOTALROW) as TOTALROWFROM( select COUNT (SEGMENT_CODE) AS TOTALROW FROM table1 WHERE SEGMENT_CODE = 'FF' UNION ALL select COUNT (SEGMENT_CODE) AS TOTALROW FROM table2 WHERE SEGMENT_CODE = 'FF')A thank you it solved.really appreciated.sabinWeb MCP
|
|
|
|
|
|