Query Question

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
wackyphill [ Di, 22 Januar 2008 15:49 ] [ ID #1913809 ]

Re: Query Question

On Jan 22, 9:49 am, wackyph... [at] yahoo.com wrote:
> 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
zeldorblat [ Di, 22 Januar 2008 17:46 ] [ ID #1913810 ]

Re: Query Question

I think you may be on to it. But I get NULL for 'NewSlnCount'. Why
would SUM report NULL?
wackyphill [ Di, 22 Januar 2008 18:21 ] [ ID #1913811 ]

Re: Query Question

Nevermind I got it working thanks to your example.

Thank you.
wackyphill [ Di, 22 Januar 2008 19:39 ] [ ID #1913812 ]
Datenbanken » comp.databases.ms-sqlserver » Query Question

Vorheriges Thema: Re: removing unused objects - SQL Server 2000 or 2005
Nächstes Thema: Variables in SQL-script SQL2005