函数:
f_intob(@dbso)
函数里面和@dbso有关的语句(简化):select * from table t
where t.dbso in (@dbso)应用程序给@dbno传递的值类似于;
='01'
='01','02'
....
='01','02','03'.......'20'传递'01'是没有关系的,
但是如果传递'01'下面的多值的话,就出现问题的(相当于多个参数了),如何修改单个参数的函数可以接受类似='01','02','03'.......'20'的参数值
f_intob(@dbso)
函数里面和@dbso有关的语句(简化):select * from table t
where t.dbso in (@dbso)应用程序给@dbno传递的值类似于;
='01'
='01','02'
....
='01','02','03'.......'20'传递'01'是没有关系的,
但是如果传递'01'下面的多值的话,就出现问题的(相当于多个参数了),如何修改单个参数的函数可以接受类似='01','02','03'.......'20'的参数值
set @dbno='01,02,03'select * from tb where charindex(','+rtrim(dbso)+',' , ','+@dbno+',')>0
----创建测试数据
if object_id('tbTest') is not null
drop table tbTest
if object_id('fnTest') is not null
drop function fnTest
GO
create table tbTest(dbso varchar(10))
insert tbTest
select '01' union all
select '02' union all
select '03' union all
select '04' union all
select '05'
GO
----创建函数
create function fnTest(@dbso varchar(100))
returns @t table(dbso varchar(10))
as
begin
insert @t
select * from tbTest where charindex(',' + dbso + ',',',' + @dbso + ',') > 0
return
end
GO
----查询
declare @dbso varchar(100)
set @dbso = '01,02,03'
select * from dbo.fnTest(@dbso)----清除测试环境
drop table tbTest
drop function fnTest/*结果
dbso
----------
01
02
03
*/