1,将循环因子1,2,3,4,5....存入一表中,用此表与目标表进行关联即可。
2,例子:提取 字符串 ‘13604784785薛小姐’非中文部分
create table #tt(n int) --循环数
declare @tt int
set @tt=1
while @tt<=200
begin
insert #tt values(@tt)
set @tt=@tt+1
END
CREATE TABLE #ts(tel VARCHAR(100))
INSERT INTO #ts VALUES ('13604784785薛小姐')
declare @string varchar(200)
SELECT TOP 1 *,SUBSTRING(tel,1,n-1) FROM (
SELECT tel,n,case when SUBSTRING(tel,n,1) LIKE '[0-9]' THEN NULL ELSE STUFF(tel,n,0,'#') END AS 'string'
FROM #ts JOIN #tt ON n < LEN(#ts.tel))m1
WHERE m1.string IS NOT null