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 |
|
-Dman100-
Posting Yak Master
210 Posts |
Posted - 2005-08-13 : 13:12:26
|
| Is is possible to combine the following two select statements into one statement?SELECT COUNT (ELIST_EMAIL_ADDR) AS intTotalFROM dbo.ELIST&SELECT ELIST_EMAIL_ADDR, ELIST_DATEFROM dbo.ELISTORDER BY ELIST_EMAIL_ADDR ASCI'm new to using COUNTI tried:SELECT COUNT (ELIST_EMAIL_ADDR) AS intTotal, ELIST_EMAIL_ADDR, ELIST_DATEFROM dbo.ELISTORDER BY ELIST_EMAIL_ADDR ASCThanks for any help.Regards,-D- |
|
|
rockmoose
SQL Natt Alfen
3279 Posts |
Posted - 2005-08-13 : 14:11:04
|
| You can use a subquery to do that.SELECT ...., (SELECT COUNT(...) FROM ...) AS TotalFROM ...ORDER BY ...Or derived tableSELECT ...., t.TotalFROM ...., (SELECT COUNT(...) AS Total FROM ...) AS tORDER BY ...Or declare a variableDECLARE @t INTSET @t = (SELECT COUNT(...) FROM ...)SELECT ..., @t AS TotalFROM ...ORDER BY ...Or...rockmoose |
 |
|
|
-Dman100-
Posting Yak Master
210 Posts |
Posted - 2005-08-13 : 15:15:19
|
| Thanks Rockmoose,I appreciate the help. Exactly what I needed.Regards,-D- |
 |
|
|
rockmoose
SQL Natt Alfen
3279 Posts |
Posted - 2005-08-13 : 19:53:43
|
You're welcome rockmoose |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-08-16 : 01:25:26
|
quote: Originally posted by -Dman100- Thanks Rockmoose,I appreciate the help. Exactly what I needed.Regards,-D-
No doubt. rockmoose is always helpful in T-sql MadhivananFailing to plan is Planning to fail |
 |
|
|
mmarovic
Aged Yak Warrior
518 Posts |
Posted - 2005-08-16 : 03:56:40
|
Be aware that: quote:
SELECT COUNT (ELIST_EMAIL_ADDR) AS intTotalFROM dbo.ELIST
is equivalent to:Select count(*) as intTotalfrom dbo.EListwhere elist_email_addr is not null |
 |
|
|
rockmoose
SQL Natt Alfen
3279 Posts |
Posted - 2005-08-16 : 06:24:27
|
quote: Originally posted by mmarovic Be aware that: quote:
SELECT COUNT (ELIST_EMAIL_ADDR) AS intTotalFROM dbo.ELIST
is equivalent to:Select count(*) as intTotalfrom dbo.EListwhere elist_email_addr is not null
Be aware that NULLS should be avoided Cheers Madhivanan!rockmoose |
 |
|
|
|
|
|
|
|