我想编写一个存储过程,其中有两个选择查询,第二个查询具有取决于第一个查询输出的where子句,如下
create procedure getRecord
As
Begin
select *
from tblUser
where userName = 'Johan'
select *
from tblDistrict
where id between @id1 and @id2
end
这里
@id1
和@id2
是第一个查询的结果表的第一个和最后一个ID 最佳答案
试试这个
create procedure getRecord
As
Begin
select * from tblDistrict where id IN (select Id from tblUser Where userName = 'Johan')
End
关于sql-server - 当第二个查询依赖于SQL Server中的第一个查询输出时,如何在存储过程中编写两个查询,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36473644/