有一个字段word是存储字符
id word
1 a
2 b
3 c
4 d
5 e 然后在存储过程
set @Test='gdakbd'
如何判断@Test的字符是否有word字段里的值
并且要等到id 号
如@Test='gdakbd'
就要按顺序的得到 4,1,2,4
id word
1 a
2 b
3 c
4 d
5 e 然后在存储过程
set @Test='gdakbd'
如何判断@Test的字符是否有word字段里的值
并且要等到id 号
如@Test='gdakbd'
就要按顺序的得到 4,1,2,4
select 1 [id],'a' word into #t
union select all 2,'b'
union select all 3,'c'
union select all 4,'d'
union select all 5,'e' --数据处理
declare @Test varchar(1000)
set @Test='gdakbd'
declare @str varchar(1000)
set @str=@test
select @Test=replace(@Test,word,cast([id] as varchar(2))+',') from #t
declare @i int
set @i=1
while @i<=len(@str)
begin
set @test=replace(@test,substring(@str,@i,1),'')
set @i=@i+1
end
set @test=left(@Test,len(@test)-1)
print @test/*结果
4,1,2,4
*/