我正在尝试使用以下查询插入表变量。 但它抛出一个错误。 请使用单个插入语句帮助插入多个选择。
DECLARE @AddressRecordsToPurge TABLE
(
RowID INT NOT NULL PRIMARY KEY IDENTITY(1,1),
GUIDValue Nvarchar(max) ,
GuidColumn Nvarchar(max) ,
GuidTable Nvarchar(max)
)
Insert Into @AddressRecordsToPurge values ( (Select
EMPLOYMENTSEQUENCENUMBER FROM ACCOUNTANTSREFERENCE WHERE
CustomerNumber = @CustomerNumber AND Customerversionnumber =
@CustomerVersionNumber AND EMPLOYMENTSEQUENCENUMBER IS NOT
NULL), 'EMPLOYMENTSEQUENC ENUMBER', 'ACCOUNTANTSREFERENCE');
我的select语句返回多个值,我想只以这种方式使用它。请帮忙!
答案 0 :(得分:4)
您的语法略有偏差:
Insert Into @AddressRecordsToPurge (GuidValue, GuidColumn, GuidTable)
SELECT EMPLOYMENTSEQUENCENUMBER, 'EMPLOYMENTSEQUENCENUMBER', 'ACCOUNTANTSREFERENCE'
FROM ACCOUNTANTSREFERENCE
WHERE CustomerNumber = @CustomerNumber
AND Customerversionnumber = @CustomerVersionNumber
AND EMPLOYMENTSEQUENCENUMBER IS NOT NULL;