dbTalk Databases Forums  

Query Question

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss Query Question in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
wackyphill@yahoo.com
 
Posts: n/a

Default Query Question - 01-22-2008 , 08:49 AM






Is it possibe to combine the results of these 2 queries into a single
result set consisting of 1 row and 2 columns (for each value)?

SELECT COUNT(*) AS 'SlnCount' FROM Request WHERE RequestTypeID = 2
SELECT COUNT(*) AS 'NewSlnCount' FROM Request WHERE RequestTypeID = 2
AND StatusID = 1


Reply With Quote
  #2  
Old   
ZeldorBlat
 
Posts: n/a

Default Re: Query Question - 01-22-2008 , 10:46 AM






On Jan 22, 9:49 am, wackyph... (AT) yahoo (DOT) com wrote:
Quote:
Is it possibe to combine the results of these 2 queries into a single
result set consisting of 1 row and 2 columns (for each value)?

SELECT COUNT(*) AS 'SlnCount' FROM Request WHERE RequestTypeID = 2
SELECT COUNT(*) AS 'NewSlnCount' FROM Request WHERE RequestTypeID = 2
AND StatusID = 1
SELECT COUNT(*) AS 'SlnCount',
SUM(CASE WHEN StatusID = 1 THEN 1 ELSE 0 END) AS 'NewSlnCount'
FROM Request
WHERE RequestTypeID = 2


Reply With Quote
  #3  
Old   
wackyphill@yahoo.com
 
Posts: n/a

Default Re: Query Question - 01-22-2008 , 11:21 AM



I think you may be on to it. But I get NULL for 'NewSlnCount'. Why
would SUM report NULL?


Reply With Quote
  #4  
Old   
wackyphill@yahoo.com
 
Posts: n/a

Default Re: Query Question - 01-22-2008 , 12:39 PM



Nevermind I got it working thanks to your example.

Thank you.

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.