sql server - Facing difficulty in column data type in SQL Unpivot query -


i not familiar sql query. have tried build query using unpivot functionality of sql server facing error says:

the type of column "u_itemmodality" conflicts type of other columns specified in unpivot list.

here query:

select      cast(unpvt.itemcode collate database_default varchar(30)) itemcode,     cast(unpvt.attribute collate database_default varchar(30)) attribute,     cast(unpvt.value collate database_default varchar(30)) value  [oitm] unpivot (     value attribute in (u_mfg_part_num, u_part_descriptor, u_itemmodality) ) unpvt inner join [@aectrandata] wi      on unpvt.itemcode = wi.u_objectkeyvalue inner join oitm im      on wi.u_objectkeyvalue = im.itemcode       wi.u_objecttype ='4' 

in query, if remove u_itemmodality run. other 2 columns have size of 100 character column have size of 30 character.

what overcome situation?

the datatype length must equal when using unpivot. see question more information. should convert u_itemmodality varchar(100) have same length other 2 columns.

select      cast(unpvt.itemcode collate database_default varchar(30)) itemcode,     cast(unpvt.attribute collate database_default varchar(30)) attribute,     cast(unpvt.value collate database_default varchar(30)) value  (     select         u_mfg_part_num,         u_part_descriptor,         u_itemmodality = convert(varchar(100), u_itemmodality)     [oitm] )t unpivot (     value attribute in (u_mfg_part_num, u_part_descriptor, u_itemmodality) ) unpvt inner join [@aectrandata] wi      on unpvt.itemcode = wi.u_objectkeyvalue inner join oitm im      on wi.u_objectkeyvalue = im.itemcode       wi.u_objecttype ='4' 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -