Whether can use SQL to achieve without stored procedure directly?
CodePudding user response:
My train of thought is directly using if.. The else..BEGIN
IF (SELECT count (*) FROM t1)=0
THEN SELECT count (*) FROM t1;
The ELSE SELECT count (*) FROM t2;
END the IF;
END;
Perform error, IF grammar mistakes, to solve
CodePudding user response:
SELECT the IIF (COUNT (*)=0, (SELECT COUNT (*) FROM t1), (SELECT COUNT (*) FROM t2)) FROM t1
The SELECT (CASE WHEN the COUNT (*)=0 THEN COUNT (*) ELSE (SELECT COUNT (*) FROM t2) END) COUNT FROM t1
CodePudding user response:
Declare @ a int
The set @ a=1
If @ a=1
The begin
Select the 'a'
End
If @ a=2
The begin
Select 'b'
End
Is that ok?
CodePudding user response:
Thinking no problem of the building Lord, is the problem writing someIF
(
SELECT COUNT (*) FROM t1
)=0
The BEGIN
SELECT COUNT (*)
The FROM t1;
END;
The ELSE
The BEGIN
SELECT COUNT (*)
The FROM t2.
END;
CodePudding user response: