1
我想與Company
從@MyList.CompanyNo
來延長ListA
,普萊舍參考代碼清單以結果從SQL/T-SQL子查詢到父select語句
數據&初始化:
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
與相應的@MyList.CompanyNo
。
謝謝,我該怎麼辦?