Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 错误:“foo”列的类型与UNPIVOT列表中指定的其他列的类型冲突_Sql_Sql Server - Fatal编程技术网

Sql 错误:“foo”列的类型与UNPIVOT列表中指定的其他列的类型冲突

Sql 错误:“foo”列的类型与UNPIVOT列表中指定的其他列的类型冲突,sql,sql-server,Sql,Sql Server,我正在取消某些列的初始化,但不幸的是,它一次又一次地返回相同的错误。 条形码列的类型为INT,我将其转换为VARCHAR50 有人能告诉我我做错了什么吗 错误如下: The type of column "BarCode" conflicts with the type of other columns specified in the UNPIVOT list. 使用“交叉应用”取消PIVOT: SELECT v.* FROM [item cross reference] icr CROS

我正在取消某些列的初始化,但不幸的是,它一次又一次地返回相同的错误。 条形码列的类型为INT,我将其转换为VARCHAR50

有人能告诉我我做错了什么吗

错误如下:

The type of column "BarCode" conflicts with the type of other columns specified in the UNPIVOT list.
使用“交叉应用”取消PIVOT:

SELECT v.* 
FROM [item cross reference] icr CROSS APPLY
     (VALUES ('CrossCode', CONVERT(VARCHAR(50), c.[cross-reference type no_]),
             ('BarCode', CONVERT(VARCHAR(50), c.[barcode type]), 
             ('CrossReference', CONVERT(VARCHAR(50), c.[cross-reference no_])), 
             ('CrossDescription', CONVERT(VARCHAR(50), c.[description]))
      ) v(waarde, kolom);
使用“交叉应用”取消PIVOT:

SELECT v.* 
FROM [item cross reference] icr CROSS APPLY
     (VALUES ('CrossCode', CONVERT(VARCHAR(50), c.[cross-reference type no_]),
             ('BarCode', CONVERT(VARCHAR(50), c.[barcode type]), 
             ('CrossReference', CONVERT(VARCHAR(50), c.[cross-reference no_])), 
             ('CrossDescription', CONVERT(VARCHAR(50), c.[description]))
      ) v(waarde, kolom);

你能发布表[项目对照]的结构吗?你能发布表[项目对照]的结构吗?
--just remove pv.  :: FOR kolom IN (**pv.**crosscode,

create table [#item cross reference]
(
[cross-reference type no_] varchar(10),
[barcode type] int,
[cross-reference no_] float,
[description] xml
);

insert into [#item cross reference]/*()*/
values('a', 100, 123, '<a>test</a>');

select *
from [#item cross reference];


SELECT * 
FROM   
(
SELECT 
    CONVERT(VARCHAR(50), c.[cross-reference type no_]) AS CrossCode, 
   CONVERT(VARCHAR(50), c.[barcode type])             AS BarCode, 
   CONVERT(VARCHAR(50), c.[cross-reference no_])      AS CrossReference, 
   CONVERT(VARCHAR(50), c.[description])              AS CrossDescription 
FROM   [#item cross reference] c
) AS pv 
UNPIVOT 
(
    waarde FOR kolom IN (CrossCode /*just remove pv.*/, BarCode, CrossReference, CrossDescription)
) AS unpvt;