Monday, January 7, 2008

SQL Server 2005 - PIVOT() sample for syslog priority code

1.)

select IpAddressSource,[1],[2],[3],[4],[5],[6],[7] from (
select IpAddressSource,PriorityCode,count(*) N from sll1
where datetimelocal >= '2008-01-01'
group by ipaddresssource,prioritycode) a
pivot (sum(n)
for PriorityCode in ([1],[2],[3],[4],[5],[6],[7])) as pvt

2.)


select IpAddressSource,[1],[2],[3],[4],[5],[6],[7] from (
select IpAddressSource,PriorityCodefrom sll1
where datetimelocal >= '2008-01-01') a
pivot ( count(PriorityCode)
for PriorityCode in ([1],[2],[3],[4],[5],[6],[7]) ) as pvt

No comments: