SELECT *
FROM [Live].[Test]
WHERE [_fk_RoadMapKey] = @_fk_RoadMapKey
SELECT @TestKey = [TestKey]
FROM [Live].[Test]
WHERE [_fk_RoadMapKey] = @_fk_RoadMapKey
SELECT *
FROM [Live].[SetofTestGrades]
WHERE [_fk_TestKey] = @TestKey
前两个语句,我们可以在分配testkey的同时进行所有测试吗
SELECT * ,@TestKey = [TestKey] FROM [Live].[Test]
WHERE [_fk_RoadMapKey] = @_fk_RoadMapKey
答案 0 :(得分:0)
您不能使用单个select语句将数据分配给变量并返回数据,如果您使用@TestKey
从另一个表中检索值,那么您可以跳过变量并使用join从另一个表中获取数据,尝试此
SELECT *
FROM [Live].[Test]
WHERE [_fk_RoadMapKey] = @_fk_RoadMapKey
SELECT S.*
FROM [Live].[SetofTestGrades] S
INNER JOIN [Live].[Test] T ON S.[_fk_TestKey] = T.[TestKey]
WHERE t.[_fk_RoadMapKey] = @_fk_RoadMapKey