日期:2014-05-18 浏览次数:20561 次
create procedure AA as begin declare @s varchar(1000) set @s = 'select ' declare @_i int declare @_len int select @_len=max(len(cityname)) from dbo.T_city set @_i=1 while @_i <= @_len begin set @s = @s + ' substring(cityname , ' + ltrim(@_i) + ' , ) ,' set @_i=@_i+1 end set @s = substring(@s , 1 , len(@s) - 1) + ' from dbo.T_city' exec cit_name end
------解决方案--------------------
--如果你的不够@_len怎么办?,也许下面的好点.
create procedure AA as begin declare @s varchar(1000) set @s = 'select ' declare @_i int declare @_len int select @_len=max(len(cityname)) from dbo.T_city set @_i=1 while @_i <= @_len begin set @s = @s + ' substring(cityname , ' + ltrim(@_i) + ' , ) ,' set @_i=@_i+1 end set @s = substring(@s , 1 , len(@s) - 1) + ' from dbo.T_city where len(cityname) >= ' + ltrim(@_len) exec cit_name end