Tag Info

New answers tagged

0

Your best bet is probably to use dynamic SQL to pivot your data. Here try this out. IF OBJECT_ID('tempdb..#tblItems') IS NOT NULL DROP TABLE #tblItems; IF OBJECT_ID('tempdb..##tblItemsTotal') IS NOT NULL DROP TABLE ##tblItemsTotal; CREATE TABLE #tblItems ( UniqueCode CHAR(4), [Description] VARCHAR(100), [Date] Date, Amount ...


0

It's impossible to get a result of yet unknown column names. SQL demands to know names and data types of columns to return at least at call time. You can either run two queries: the first to build your statement and the second to execute it. Or you try this - if it's enough to have column names in the first row of data: SELECT * FROM crosstab( $$ ...


0

I think I might have figured this out using Postgresql's array_agg, but with a big downside, so I'd still be interested in seeing other answers. SELECT period, ("array_agg"(ROW(motive_value, motive_name, sample_size)))[1:5] AS sample_list FROM ( SELECT period, motive_value, COUNT(motive_value) AS ...



Top 50 recent answers are included