0

次の挿入ステートメントを機能させようとしていますが、うまくいきませんでした。色々と調べたり試したりしましたが、解決には至りませんでした。リテラル文字列 NA を列に割り当てる方法はありますか?

qryALL (@pPK BIGINT,@pAL FLOAT,@pFK BIGINT)
AS
DECLARE @query  AS NVARCHAR(MAX)

SET @query = 'INSERT INTO tblTPF ( fldFPK, fldPK, fldDTA, fldCI, fldMD, fldME, 
fldIQ, fldSD, fldND, fldNI, fldNL, fldMI, fldMA, fldUN, fldAV )
SELECT '+ Convert(varchar,@pFK) +' AS sFPK, '+ Convert(varchar,@pPK) +' AS sPK, 
GETDATE() AS sDate, '+ Convert(varchar,@pAL) +' AS sAL, -254 AS sMD, -254 AS sME,
-254 AS sIQ, -254 AS sSD, 0 AS sND, 0 AS sNI, 0 AS sNL, -254 AS sMI, -254 AS sMA, 
NA AS sUN, 0 AS sAV;'

execute sp_executesql @query
4

1 に答える 1

1

リテラル文字列は一重引用符で囲む必要があります。たとえばselect 'NA' as sUN、文字列内のリテラル文字列は二重の一重引用符で囲む必要があります。

SET @query = 'INSERT INTO tblTPF ( fldFPK, fldPK, fldDTA, fldCI, fldMD, fldME, 
fldIQ, fldSD, fldND, fldNI, fldNL, fldMI, fldMA, fldUN, fldAV )
SELECT '+ Convert(varchar,@pFK) +' AS sFPK, '+ Convert(varchar,@pPK) +' AS sPK, 
GETDATE() AS sDate, '+ Convert(varchar,@pAL) +' AS sAL, -254 AS sMD, -254 AS sME,
-254 AS sIQ, -254 AS sSD, 0 AS sND, 0 AS sNI, 0 AS sNL, -254 AS sMI, -254 AS sMA, 
''NA'' AS sUN, 0 AS sAV;'
于 2013-08-26T20:13:51.437 に答える