接收变量的数据类型varchar不等于列的数据类型nvarchar

时间:2016-03-16 07:57:53

标签: sql sql-server tsql

我收到此消息的错误消息。错误消息是:

  

接收变量的数据类型varchar不等于数据类型   列的nvarchar' VEHICLE_ID2_FW'

请帮忙,谢谢

DECLARE @IMPORTID INT
DECLARE @LASTID INT
DECLARE @VEHICLEID VARCHAR (20)

SELECT @LASTID = (SELECT LAST_REFERENCE_FW FROM REFERENCE_FW WHERE RECORD_TYPE_FW = 'VEHICLES_ORDERS_FW' AND REFERENCE_FIELD_FW = 'VEHICLE_ID2_FW' AND ARCHIVE_STATUS_FW ='N')
SELECT @IMPORTID = (SELECT IMPORT_ID_FW FROM VEHICLES_ORDERS_FW WHERE RECORD_NUMBER_FW = %RECORD_NUMBER_FW%)
SELECT @VEHICLEID = (SELECT VEHICLE_ID2_FW FROM VEHICLES_ORDERS_FW WHERE RECORD_NUMBER_FW = %RECORD_NUMBER_FW%)

IF @IMPORTID IS NOT NULL AND @VEHICLEID IS NULL

BEGIN
UPDATE VEHICLES_ORDERS_FW
SET @LASTID = VEHICLES_ORDERS_FW.VEHICLE_ID2_FW = @LASTID+1
FROM VEHICLES_ORDERS_FW
WHERE RECORD_NUMBER_FW = %RECORD_NUMBER_FW%;

UPDATE VEHICLES_ORDERS_FW
SET VEHICLES_ORDERS_FW.VEHICLE_ID2_FW = 'FW'+VEHICLE_ID2_FW
FROM VEHICLES_ORDERS_FW
WHERE RECORD_NUMBER_FW = %RECORD_NUMBER_FW%

END

3 个答案:

答案 0 :(得分:0)

Mabey在这里是个问题:

set @LASTID = VEHICLES_ORDERS_FW.VEHICLE_ID2_FW = @LASTID + 1
如果你提供表结构,

会很好。

答案 1 :(得分:0)

如果您不想更改表数据类型。您可以使用CASTCONVERT

键入广告列

答案 2 :(得分:0)

尝试使用以下脚本更改脚本

DECLARE @IMPORTID INT
DECLARE @LASTID INT
DECLARE @VEHICLEID VARCHAR (20)

SELECT @LASTID = (SELECT LAST_REFERENCE_FW FROM REFERENCE_FW WHERE RECORD_TYPE_FW like N'VEHICLES_ORDERS_FW' AND REFERENCE_FIELD_FW LIKE N'VEHICLE_ID2_FW' AND ARCHIVE_STATUS_FW  LIKE N'N')

SELECT @IMPORTID = (SELECT IMPORT_ID_FW FROM VEHICLES_ORDERS_FW WHERE CAST(RECORD_NUMBER_FW  AS NVARCHAR) LIKE CONCAT(N'%', CAST(RECORD_NUMBER_FW AS NVARCHAR),N'%'))

SELECT @VEHICLEID = (SELECT VEHICLE_ID2_FW FROM VEHICLES_ORDERS_FW WHERE CAST(RECORD_NUMBER_FW  AS NVARCHAR)  = CONCAT(N'%', CAST(RECORD_NUMBER_FW AS NVARCHAR),N'%'))

IF @IMPORTID IS NOT NULL AND @VEHICLEID IS NULL

BEGIN
UPDATE VEHICLES_ORDERS_FW
SET @LASTID = @LASTID+1
FROM VEHICLES_ORDERS_FW
WHERE CAST(RECORD_NUMBER_FW  AS NVARCHAR) LIKE CONCAT(N'%', CAST(RECORD_NUMBER_FW AS NVARCHAR),N'%');

UPDATE VEHICLES_ORDERS_FW
SET VEHICLES_ORDERS_FW.VEHICLE_ID2_FW = CONCAT(N'FW',VEHICLE_ID2_FW)
FROM VEHICLES_ORDERS_FW
WHERE CAST(RECORD_NUMBER_FW  AS NVARCHAR) LIKE CONCAT(N'%', CAST(RECORD_NUMBER_FW AS NVARCHAR),N'%');