假设我们有一个Emp包含EmpId, Manager, Subb三列的表.
Manager是EmpId经理时为1 ,同样为subb.
需要表中的manager和subb的数量.
我们可以将这两个查询合并到一个SELECT查询中吗?(想要扫描一次表)
select count(*) as ManagerNumber from Emp where Manager=1
select count(*) as Subordinate from Emp where Subb=1.
Run Code Online (Sandbox Code Playgroud) 我想使用CASE语句,例如下面的代码或实现上述方案的任何其他建议。
我将在某些SP中使用此where @UpdateStatus参数,并将其作为输入参数。
请提出建议。
DECLARE @UpdateStatus nvarchar(20)
SET @UpdateStatus='P'
CASE
WHEN @UpdateStatus='P' THEN
BEGIN
BEGIN TRAN
Print 'A' --Update some table
COMMIT
END
WHEN @UpdateStatus='F' THEN
BEGIN
BEGIN TRAN
Print 'B' --Update some table
COMMIT
END
END
Run Code Online (Sandbox Code Playgroud)