求助sql server一个存储过程的问题

2025-01-01 00:26:15
推荐回答(2个)
回答1:

判断变量是否为null要用is null的
如下:
CREATE procedure lianxi
@transtype varchar(20) ,
@cabit_32 varchar(20) = null
as
if @cabit_32 is null
begin
select * from zhilian
end
else
begin
select * from zhilian
where transtype = @transtype
end
GO

回答2:

CREATE or REPLACE procedure lianxi
@transtype varchar(20) ,
@cabit_32 varchar(20) = ''
as
if @cabit_32 = ''
begin
select * from zhilian
end
else
begin
select * from zhilian where transtype = @transtype
end
GO