[Solved] SQL Query to Transpose Column Counts to Row Counts

These type of queries are easier to make with an aim of GROUP BY, like this: Select case when profile.foo ~* ‘5.0.2195’ then ‘Win2k’ when profile.foo ~* ‘5.1.2600’ then ‘WinXP’ when profile.foo ~* ‘5.2.3790’ then ‘W2k3’ when (profile.foo ~* ‘6.0.6000’ or profile.foo ~* ‘6.0.6001’ or profile.foo ~* ‘6.0.6002’) then ‘Vista’ when (profile.foo ~* ‘6.1.7600’ or … Read more

[Solved] T-SQL (Un)Pivot Table

I usually use dynamic sql. Something like this create table #T ( ID int, aText1 varchar(4), aText2 varchar(4), aInt1 int, aInt2 int ) insert into #T select 1, ‘ABC1’, ‘XYZ1’, 2, 20 union select 2, ‘ABC1’, ‘XYZ2’, 3, 25 union select 3, ‘ABC2’, ‘XYZ2’, 1, 30 union select 4, ‘ABC2’, ‘XYZ1’, 4, 35 declare @sql … Read more