create function fun_getygqxisexist(@vYgbm varchar(15),@vQxbm varchar(15))
returns int
as
begin
declare @Sql nvarchar(4000)
declare @count int
declare @da int
declare @yg int select @da=count(f_qxbm) from tbda_qx where f_qxbm like @vQxbm+'%'
select @yg=count(f_qxbm) from tbqx_yg where f_ygbm=@vYgbm and f_qxbm like @vQxbm+'%'
select @count=case when @da=@yg then 2 when @yg=0 then 0 else 1 end
return(isnull(@count,0))
end意图是like后面是否需要加引号,还是像上面这样就是正确的
returns int
as
begin
declare @Sql nvarchar(4000)
declare @count int
declare @da int
declare @yg int select @da=count(f_qxbm) from tbda_qx where f_qxbm like @vQxbm+'%'
select @yg=count(f_qxbm) from tbqx_yg where f_ygbm=@vYgbm and f_qxbm like @vQxbm+'%'
select @count=case when @da=@yg then 2 when @yg=0 then 0 else 1 end
return(isnull(@count,0))
end意图是like后面是否需要加引号,还是像上面这样就是正确的
returns int
as
begin
declare @Sql nvarchar(4000)
declare @count int
declare @da int
declare @yg int select @da='count(f_qxbm) from tbda_qx where f_qxbm like '''+ @vQxbm+'%'''
select @yg='count(f_qxbm) from tbqx_yg where f_ygbm=@vYgbm and f_qxbm like '''+ @vQxbm+'%'''
select @count=case when +@da=@yg then 2 when @yg=0 then 0 else 1 end
return(isnull(@count,0))
end
ps:
在存储过程里面需要动态组建sql语句时需要后面加引号