如何将声明的var插入临时表?
DECLARE @ConcatString VARCHAR(4000)
SELECT @ConcatString = COALESCE(@ConcatString + ', ', '') + LanguageName FROM EmployeeLanguage where EmployeeId=10504
SELECT @ConcatString AS Language
GO
DECLARE @T1 TABLE (
Item1 BigInt,
Item2 VARCHAR(200)
)
INSERT INTO @T1 select 1,(SELECT @ConcatString AS Language ) as t
select * from @T1
答案 0 :(得分:3)
删除GO
声明。它将查询分为两个批次,变量仅限于他们在其中创建的批次。
您也不需要子选择。只需执行以下操作:
Insert Into @T1
(Item1, Item2)
Select 1, @ConcatString;
答案 1 :(得分:0)
对查询进行以下更改
1. Remove the keyword GO.
2. Item2 VARCHAR(200) column size to VARCHAR(4000)
if @ConcatStringlength exceed the current Item2 VARCHAR(200)