我的问题是我可以在一个语句中完成这两个选择的功能并摆脱 IF 吗?
DECLARE @recID INT;
--Case 1
SET @recID = null;
--Case 2
--SET @recID = 117;
IF @recID is null
BEGIN
select * from myTable WHERE [myIDcolumn] is null -- works when recID is null
END
ELSE
BEGIN
select * from myTable WHERE [myIDcolumn] = @recID -- works when recID is number
END