446
社区成员
发帖
与我相关
我的任务
分享
declare @index int
declare @length int
declare @str nvarchar(200)
declare @newStr nvarchar(200)
declare @temp nvarchar(20)
set @index=1
set @newStr=''
set @str=lower('test-aBc 666 &()_Abc')
select @length=len(@str)
while @index<=@length begin
set @temp=substring(@str,@index,1)
if @temp like '%[a-z]%' or @temp like '%[0-9]%' or @temp like '%-%' begin
set @newStr+=@temp
end
else if @temp like '% %' begin
set @newStr+='-'
end
set @index+=1
end
print(@newStr)