tsql - Pivot with Temp Table (definition for column must include data type) -- SQL Server 2008 -


the following returning 2 errors: 'the definition column '0.63' must include data type.' 'the select list insert statement contains fewer items insert list. number of select values must match number of insert columns.'

i understand need assign data type columns being inserted temp table don't quite understand how dynamic code however. if explanation on how @cols variable code working , specific issue. fldpk data type int , pivot fields i.e. @cols, float data type.

declare @cols nvarchar(max),         @query  nvarchar(max);      select @cols = stuff((select distinct ',' + quotename(fldci)                          fn_qryt_1()                 xml path(''), type                 ).value('.', 'nvarchar(max)')              ,1,1,'')      set @query = 'select fldpk, ' + @cols + '                                           (                     select   fldpk                             ,fldni                             ,fldci                     fn_qryt_1()                         ) x                     pivot                     (                         sum(fldni) fldci in (' + @cols + ')                     ) p                   declare @tps table                 (                     ' + @cols + '                  )                  insert @tps (' + @cols + ')                  select fldpk, [1], [2], [3], [4], [5]                 @tps                 ((([1])<10)) or ((([2])<10)) or ((([3])<10))'                  exec sp_executesql @query 


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -