日期:2014-05-18  浏览次数:20846 次

返回的是一句执行语句 要看到试图应该怎么写?
drop procedure cit_namee
create procedure cit_namee
as begin 
declare @_i int
declare @_len int
declare @s varchar(1000)
declare @b varchar(2)
set @b=1
set @s='select '
select @_len=max(len(cityname)) from dbo.T_city 
set @_i=1 
while @_i <= @_len
begin
set @s = @s + ' substring(cityname , ' + ltrim(@_i) + ','+@b+' ) as 第'+ltrim(@_i) +'个字节 ,'
-- select substring(cityname, @_i,1) from dbo.T_city 
set @_i=@_i+1
end
set @s = substring(@s , 1 , len(@s) - 1) + ' from dbo.T_city'
print @s
end 
exec cit_namee 
返回的是一句执行语句 要看到试图应该怎么写?

------解决方案--------------------
SQL code
drop procedure cit_namee
create procedure cit_namee
as begin  
declare @_i int
declare @_len int
declare @s varchar(1000)
declare @b varchar(2)
set @b=1
set @s='select '
select @_len=max(len(cityname)) from dbo.T_city  
set @_i=1  
while @_i <= @_len
begin
set @s = @s + ' substring(cityname , ' + ltrim(@_i) + ','+@b+' ) as 第'+ltrim(@_i) +'个字节 ,'
-- select substring(cityname, @_i,1) from dbo.T_city  
set @_i=@_i+1
end
set @s = substring(@s , 1 , len(@s) - 1) + ' from dbo.T_city'
--print @s
exec (@s)
end  
go