Please start any new threads on our new site at http://forums.sqlteam.com. 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
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Adding counts of Select results
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

jbosco1988
Starting Member

USA
46 Posts

Posted - 04/04/2013 :  18:11:47  Show Profile  Send jbosco1988 a Yahoo! Message  Reply with Quote
I am trying to add then divide Select counts. For Example something like this:

SELECT (SELECT COUNT(*) FROM TABLE1) + (SELECT COUNT(*) FROM TABLE2)


/

SELECT (SELECT COUNT(*) FROM TABLE3) + (SELECT COUNT(*) FROM TABLE4)


where would I place the opening and ending parentheses?

Thanks to all in advance

chadmat
The Chadinator

USA
1974 Posts

Posted - 04/04/2013 :  18:27:33  Show Profile  Visit chadmat's Homepage  Reply with Quote
If I understand correctly, you was to divide the 2 totals, in that case, this should work:

SELECT ((SELECT COUNT(*) FROM TABLE1) + (SELECT COUNT(*) FROM TABLE2))


/

((SELECT COUNT(*) FROM TABLE3) + (SELECT COUNT(*) FROM TABLE4) )



-Chad
Go to Top of Page

jbosco1988
Starting Member

USA
46 Posts

Posted - 04/04/2013 :  19:08:08  Show Profile  Send jbosco1988 a Yahoo! Message  Reply with Quote
Ok thanks Chad for the quick response!!!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52326 Posts

Posted - 04/05/2013 :  01:11:12  Show Profile  Reply with Quote
if you want decimal portion also it should be

SELECT ((SELECT COUNT(*) FROM TABLE1) + (SELECT COUNT(*) FROM TABLE2)) * 1.0


/

((SELECT COUNT(*) FROM TABLE3) + (SELECT COUNT(*) FROM TABLE4) )


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
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.08 seconds. Powered By: Snitz Forums 2000