This is my sample table, I want to pivot the category column and get the sales, stock and target as rows I want the sample output in this form as shown in the below wherein the categories are in , Firstly, if you need to order the pivot column list when building it, you need to remember the stupid MSSQL hack of including offset 0 rows. Secondly, you also have to remember the additional stupid MSSQL hack of including the unnecessary table alias t., So, when MSSQL does pivot for no record, MSSQL always shows NULL for MAX, SUM, (aggregate functions). None of above solutions (IsNull ( [AZ], 0)) works for me, but I do get ideas from these solutions., GROUP BY Username PIVOT BY CAST(LoginDate AS DATE) i just can't seem to wrap my head out the PIVOT syntax; in order to tell SQL Server what column values should become columns, and what column values the aggregation happens over. Everyone seems to want to hard-code the columns, or invokes some XML queries. i just want to do a pivot!, 9 The OP didn't actually need to pivot without agregation but for those of you coming here to know how see: sql parameterised cte query The answer to that question involves a situation where pivot without aggregation is needed so an example of doing it is part of the solution., I´m trying to PIVOT some data in a table, but I cannot do it because I do not find the way to do it using varchar columns. I have this table: And what I need is this: I need to use the 'ug_label'.