Tag Info

New answers tagged

4

I suggest a radially new approach with crosstab() from the additional module tablefunc. You need to install it once per database. Detailed instructions: PostgreSQL Crosstab Query SELECT k.name, keyword_id, project_id, now()::date AS the_date , t AS today, y As yesterday, w AS week, m AS month FROM crosstab( $$ SELECT rn , ...


1

The problem is with your CROSS APPLY or unpivot. When you unpivot data it will then be placed in the same column so the datatype must be the same. Your code is using to unpivot is: cross apply ( select ''RoomNo'', RoomNo union all select ''Beds'', Beds union all select ''[Description]'', [Description] union all select ''SharingType'', SharingType ...


4

Since you want to use PIVOT to get the result and you need to to this dynamically, I would always suggest writing a static PIVOT query first, this allows you to get the syntax correct before trying to convert it to dynamic SQL. The desired output shows that you want to PIVOT on two columns, RoomNo and Beds - as a result you'll need to unpivot these columns ...



Top 50 recent answers are included