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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Syntax

Author  Topic 

Mondeo
Constraint Violating Yak Guru

287 Posts

Posted - 2009-01-21 : 15:37:43
Hi, i'm struggling to get this query to run, could someone tell me the correct syntax for this type of command. Thanks

SELECT * FROM(
SELECT COUNT (id) as helm FROM tblHELMAccounts,
SELECT COUNT (id) as pop3 FROM tblPOP3Accounts,
SELECT COUNT (id) as sqldb FROM tblSQLDatabases,
SELECT COUNT (id) as google FROM tblGoogleAccounts
)

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-01-21 : 15:40:11
SELECT (Query1) AS CountHELMAccounts, (Query2) AS ..., (Query3) AS ..., (Query4) AS ...

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-01-21 : 15:41:37
The above will put them into separate columns. If you instead want them as separate rows in one column, you could do it like this instead:

SELECT 'HELMAccounts' AS TableName, (Query1) AS TableCount
UNION ALL
SELECT ..., (Query2)
UNION ALL
...


Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2009-01-21 : 16:12:19
If you want in separate columns,

SELECT
COUNT (id) as helm ,
pop3 =(SELECT COUNT ([id]) FROM tblPOP3Accounts),
sqldb =(SELECT COUNT ([id]) FROM tblSQLDatabases),
google=(SELECT COUNT ([id]) FROM tblGoogleAccounts)
FROM tblHELMAccounts
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-01-21 : 16:14:21
Which is what I showed in my first post.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -