/*
select dbo.GetCheckTab('SortValue1,SortValue3,SortValue8,SortValue9,SortValue10,',5)
*/
create function GetCheckTab
(
@TbNames nvarchar ( 500 ), -- 查询字符串(逗号分隔)
@Tbi int -- 用于监测类别循环(用于@TbNames的循环)
)
returns nvarchar ( 100 )
as
begin
declare @NowCheckTab nvarchar ( 200 ) -- 返回表名值
declare @DealTbNames nvarchar ( 200 ) -- 处理后的字符串
declare @Start int -- 开始截取位置
declare @end int -- 结束截取位置
declare @i int -- 循环次数
set @i = 0
set @DealTbNames = @TbNames
while @i < @Tbi - 1
begin
set @Start = charindex ( ' , ' , @DealTbNames ) + 1
set @DealTbNames = substring ( @DealTbNames , @Start , len ( @DealTbNames ))
set @i = @i + 1
end
set @end = charindex ( ' , ' , @DealTbNames )
set @NowCheckTab = substring ( @DealTbNames , 0 , @end )
return @NowCheckTab
end
执行结果:sortvalue10
select dbo.GetCheckTab('SortValue1,SortValue3,SortValue8,SortValue9,SortValue10,',5)
*/
create function GetCheckTab
(
@TbNames nvarchar ( 500 ), -- 查询字符串(逗号分隔)
@Tbi int -- 用于监测类别循环(用于@TbNames的循环)
)
returns nvarchar ( 100 )
as
begin
declare @NowCheckTab nvarchar ( 200 ) -- 返回表名值
declare @DealTbNames nvarchar ( 200 ) -- 处理后的字符串
declare @Start int -- 开始截取位置
declare @end int -- 结束截取位置
declare @i int -- 循环次数
set @i = 0
set @DealTbNames = @TbNames
while @i < @Tbi - 1
begin
set @Start = charindex ( ' , ' , @DealTbNames ) + 1
set @DealTbNames = substring ( @DealTbNames , @Start , len ( @DealTbNames ))
set @i = @i + 1
end
set @end = charindex ( ' , ' , @DealTbNames )
set @NowCheckTab = substring ( @DealTbNames , 0 , @end )
return @NowCheckTab
end