以下のような行を持つクエリがあります。
CAST(REPLACE(CAST(ORDER_NOTES.BLOBDATA AS VARCHAR(250)), CHAR(13)+CHAR(10), '') AS NVARCHAR(250)) AS ORDER_NOTES
この行はSELECT
ステートメントでは正常に機能しますがINSERT INTO
、このクエリで を使用すると、次のようになります。
Msg 8115, Level 16, State 6, Line 1
Arithmetic overflow error converting nvarchar to data type numeric.
The statement has been terminated.
列のターゲット データ型はNVARCHAR(250)
.
この問題を解決するために私ができることはありますか?
以下の完全なクエリ(置換するかのように選択した最後のフィールドがNULLであると確信しています。エラーは発生しません)
INSERT INTO T_SALES_ORDERS
SELECT
R_SORD.SORDIDX,
R_SORDD.SORDDIDX,
R_SOZD.SOZDIDX,
T_PRODUCTS.SKUIDX,
CAST(R_SORD.NUM AS NVARCHAR(250)) AS LEGACY_NUMBER,
CAST(R_SORD.NUM AS NVARCHAR(250)) AS EXTERNAL_REFERENCE_NUMBER,
CAST(R_SORD.CORDER AS NVARCHAR(250)) AS CUSTOMER_ORDER_NUMBER,
CAST(T_CUST.CUSTOMER_CODE AS NVARCHAR(250)) AS CUSTOMER_CODE,
CAST(BILLTO.CUSTOMER_CODE AS NVARCHAR(250)) AS BILLTO_CODE,
CAST(DC.CUSTOMER_CODE AS NVARCHAR(250)) AS DC_CODE,
CAST(CONVERT(CHAR(10), R_SORD.ODAT, 103) AS NVARCHAR(250)) AS ORDER_DATE,
CAST(CONVERT(CHAR(10), R_SORD.DUEF, 103) AS NVARCHAR(250)) AS DUE_DATE,
CAST(CONVERT(CHAR(10), R_SORD.CAND, 103) AS NVARCHAR(250)) AS CANCEL_DATE,
CAST(M_SO_TYPE.AP21_CODE AS NVARCHAR(250)) AS SO_TYPE,
CAST(NULL AS NVARCHAR(250)) AS BARCODE,
CAST(T_PRODUCTS.PRODUCT_CODE AS NVARCHAR(250)) AS STYLE_CODE,
CAST(T_PRODUCTS.COLOUR_CODE AS NVARCHAR(250)) AS COLOUR_CODE,
CAST(T_PRODUCTS.SIZE_CODE AS NVARCHAR(250)) AS SIZE_CODE,
CAST(R_SOZD.PRICE AS NVARCHAR(250)) AS PRICE,
CAST(CAST(R_SOZD.QTY AS INT) AS NVARCHAR(250)) AS QTY,
CAST('19' AS NVARCHAR(250)) AS REF1,
CAST(NULL AS NVARCHAR(250)) AS LEGACY_REF1,
CAST(NULL AS NVARCHAR(250)) AS REF2,
CAST(NULL AS NVARCHAR(250)) AS LEGACY_REF2,
CAST('Standard' AS NVARCHAR(250)) AS REF3,
CAST(NULL AS NVARCHAR(250)) AS LEGACY_REF3,
CAST(M_PROMOTION.AP21_CODE AS NVARCHAR(250)) AS REF4,
CAST(PROMOTION.CODE AS NVARCHAR(250)) AS LEGACY_REF4,
CAST(M_ORDER_SEASON.AP21_CODE AS NVARCHAR(250)) AS REF5,
CAST(ORDER_SEASON.CODE AS NVARCHAR(250)) AS LEGACY_REF5,
CAST(NULL AS NVARCHAR(250)) AS REF6,
CAST(NULL AS NVARCHAR(250)) AS LEGACY_REF6,
CAST(NULL AS NVARCHAR(250)) AS REF7,
CAST(NULL AS NVARCHAR(250)) AS LEGACY_REF7,
CAST(NULL AS NVARCHAR(250)) AS REF8,
CAST(NULL AS NVARCHAR(250)) AS LEGACY_REF8,
CAST(NULL AS NVARCHAR(250)) AS REF9,
CAST(NULL AS NVARCHAR(250)) AS LEGACY_REF9,
CAST(NULL AS NVARCHAR(250)) AS REF10,
CAST(NULL AS NVARCHAR(250)) AS LEGACY_REF10,
CAST(REPLACE(CAST(R_SORD.DELINS AS VARCHAR(250)), CHAR(13)+CHAR(10), ' ') AS NVARCHAR(250)) AS DELIVERY_INSTRUCTIONS,
CAST(REPLACE(CAST(ORDER_NOTES.BLOBDATA AS VARCHAR(250)), CHAR(13)+CHAR(10), '') AS NVARCHAR(250)) AS ORDER_NOTES
FROM
R_SORD
INNER JOIN
R_SORDD ON
R_SORDD.SORDIDX = R_SORD.SORDIDX
AND R_SORDD.ACTIVE = 1
INNER JOIN
R_SOZD ON
R_SOZD.SORDDIDX = R_SORDD.SORDDIDX
AND R_SOZD.ACTIVE = 1
LEFT OUTER JOIN
R_REFCODE SO_TYPE ON
SO_TYPE.RCIDX = R_SORD.TYPE
LEFT OUTER JOIN
M_SO_TYPE ON
M_SO_TYPE.LEGACY_CODE = SO_TYPE.CODE
LEFT OUTER JOIN
T_CUST ON
T_CUST.CUSTIDX = R_SORD.CUSTIDX
LEFT OUTER JOIN
T_CUST BILLTO ON
BILLTO.CUSTIDX = R_SORD.BILLTO
LEFT OUTER JOIN
T_CUST DC ON
DC.CUSTIDX = R_SORD.DC
LEFT OUTER JOIN
T_PRODUCTS ON
T_PRODUCTS.SKUIDX = R_SOZD.SKUIDX
LEFT OUTER JOIN
R_BLOBTBL ORDER_NOTES ON
ORDER_NOTES.BLOBIDX = R_SORD.NOTESIDX
LEFT OUTER JOIN
R_REFCODE PROMOTION ON
PROMOTION.RCIDX = R_SORD.REF4
LEFT OUTER JOIN
M_PROMOTION ON
M_PROMOTION.LEGACY_CODE = PROMOTION.CODE
LEFT OUTER JOIN
R_REFCODE ORDER_SEASON ON
ORDER_SEASON.RCIDX = R_SORD.REF1
LEFT OUTER JOIN
M_ORDER_SEASON ON
M_ORDER_SEASON.LEGACY_CODE = ORDER_SEASON.CODE
WHERE
R_SORD.TYP = 1
AND R_SORD.ACTIVE = 1
AND R_SOZD.QTY > 0