我想使用来自ListA
的{{1}}扩展Company
,请参阅代码清单
数据与安培;初始化:
@MyList.CompanyNo
起点(这有效):
begin /*Just the init data*/
DECLARE @MyList TABLE (Mail nvarchar(max), CompanyNo int)
INSERT INTO @MyList VALUES ('...com',20)
INSERT INTO @MyList VALUES ('...com',230)
INSERT INTO @MyList VALUES ('...com',120)
INSERT INTO @MyList VALUES ('...com',223)
end
--DECLARE
DECLARE @ListA TABLE (Id nvarchar(max), Mail nvarchar(max))
DECLARE @ListB TABLE (Id nvarchar(max), Mail nvarchar(max),Company int)
我试图通过以下方式进行:
INSERT INTO @ListA(Id,Mail) select someId,name from [somedb].[dbo].aers where name IN (SELECT Mail FROM @MyList)
所以实际上我想用INSERT INTO @ListB(Id,Mail,Company) select someId,name,@MyList.CompanyNo from [somedb].[dbo].aers where name IN (SELECT Mail FROM @MyList)
来对ListB
进行扩展。
谢谢,我该怎么办?
答案 0 :(得分:0)
您可以根据JOIN
WHERE
INSERT INTO @ListB(Id,Mail,Company)
select a.someId,a.name,m.CompanyNo
from [somedb].[dbo].aers a
join @MyList m
ON a.name = m.Mail;