sql - The type of column "Change_Date" conflicts with the type of other columns specified in the UNPIVOT list -


having problems unpivot , not sure why. understand column types need same , think have sorted.

table

create table [dbo].[zztmp1]( [project_number] [varchar](50) null, [changed_design_status] [varchar](50) null, [changed_cost] [decimal](38, 4) null, [change_date] [varchar](8) null ) on [primary] 

script

select   project_number,  columnname, value, change_date (   select project_number,     changed_design_status ,        cast(changed_cost varchar(50)) changed_cost,    cast(change_date varchar(50)) change_date   zztmp1 ) d unpivot (   value    columnname in ( changed_design_status-- ,changed_cost   ) ) unpiv; 

when adding change_cost in error :

msg 8167, level 16, state 1, line 15 type of column "changed_cost" conflicts type of other columns specified in unpivot list.

if change order , run change_cost works fine. seems issue when have multiple columns, mising.

any advice appreciated.

thanks

i find easier unpivot using cross apply:

select z.project_number, v.columnname, v.value, z.change_date zztmp1 z outer apply      (values ('changed_cost', cast(changed_cost varchar(50)) ),              ('changed_design_status', cast(changed_design_status varchar(50)) )      ) v(columnname, value); 

in case, has type of changed_design_status.


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -