I have the following SQL statement..
select month(dbo.udfAddUTCBias(start_date_time, 180)) as report_month, direction as direction, count(*) as total_records from traffic with (nolock) where dbo.udfAddUTCBias(start_date_time, 180) >= '2/24/2007' and dbo.udfAddUTCBias(start_date_time, 180) < DateAdd(dd, 1, '2/24/2007') group by month(dbo.udfAddUTCBias(start_date_time, 180)), direction
but the result of the direction field is 1 and 0..
however, I need to show inbound when the result is 0 and outbound when the result is 1 without changing the actual data in the table.
You could use CASE keyword: http://msdn2.microsoft.com/en-us/library/aa258235(SQL.80).aspxselect month(dbo.udfAddUTCBias(start_date_time, 180)) as report_month
, case direction
when 0 then 'inbound'
when 1 then 'outbound'
end
as direction
, count(*) as total_records from traffic with (nolock) where dbo.udfAddUTCBias(start_date_time, 180) >= '2/24/2007' and dbo.udfAddUTCBias(start_date_time, 180) < DateAdd(dd, 1, '2/24/2007') group by month(dbo.udfAddUTCBias(start_date_time, 180)), direction
No comments:
Post a Comment