-5
 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
4

1 回答 1

0

您不能将数据分配给变量并使用单个 select 语句返回数据,如果您使用@TestKey从另一个表中检索值,那么您可以跳过变量并使用连接从另一个表中获取数据,试试这个

 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
于 2013-04-18T18:22:32.710 回答