Click to See Complete Forum and Search --> : How Do I join all this


Bill Crawley
July 18th, 2005, 05:33 AM
select count(*) as printed from quote_request_table
where convert(varchar,request_date,103) = convert(varchar,getdate(),103) and Status = 1

select count(*) as errors from quote_request_table
where convert(varchar,request_date,103) = convert(varchar,getdate(),103) and Status = 2

select count(*) as reprint from quote_request_table
where convert(varchar,request_date,103) = convert(varchar,getdate(),103) and Status = 3

select count(*) as totals from quote_request_table
where convert(varchar,request_date,103) = convert(varchar,getdate(),103)

This is SQLServer 2000

I want a result returned for each of the above statements in a single line. Union doesn't work because if say the first 2 are 0, 3rd is 3 and the 4th is 10, then I only get three results being returned 0,3,10 when I want 0,0,3,10

Thanks

wildfrog
July 18th, 2005, 05:53 AM
With subqueries that return 1 value you can:

select
(inner select #1),
(inner select #2),
(inner select #3)

or in your case, something like:

select
(select count(*) from quote_request_table where convert(varchar, request_date, 103) = convert(varchar, getdate(), 103) and Status = 1) as printed,
(select count(*) from quote_request_table where convert(varchar, request_date, 103) = convert(varchar, getdate(), 103) and Status = 2) as errors,
(select count(*) from quote_request_table where convert(varchar, request_date, 103) = convert(varchar, getdate(),103) and Status = 3) as reprint,
(select count(*) from quote_request_table where convert(varchar, request_date, 103) = convert(varchar, getdate(), 103)) as totals

- petter

Bill Crawley
July 18th, 2005, 08:32 AM
Thanks very much. Works a treat