我把一个游标写在一个存储过程中.要实现的是把Users字段里的所有字段取出来,[email protected]?想通过print @SqlStr把这个代码打印出来.但是执行成功就是没有显示?
if exists(select name from sysobjects where name= 'test ' and type= 'p ')
drop proc test
go
create proc test
@SearchStr varchar(255)
as
declare @SqlStr varchar(1000)
declare my_cursor cursor scroll for select name from syscolumns where id=object_id( 'Users ')
open my_cursor
declare @name sysname
fetch next from my_cursor into @name
while(@@fetch_status=0)
begin
/*print '字段: ' + @name*/
set @[email protected]+ ' '[email protected]+ ' like % '[email protected]+ '% '
fetch next from my_cursor into @name
end
/*fetch first from my_cursor into @name*/
/*print @name*/
close my_cursor
deallocate my_cursor
print @SqlStr
------解决方案--------------------
[email protected] ' '
------解决方案--------------------
if exists(select name from sysobjects where name= 'test ' and type= 'p ')
drop proc test
go
create proc test
@SearchStr varchar(255)
as
declare @SqlStr varchar(1000)
set @SqlStr= ' ' ---这个地方先赋个初始值
declare my_cursor cursor scroll for select name from syscolumns where id=object_id( 'Users ')
open my_cursor
declare @name sysname
fetch next from my_cursor into @name
while(@@fetch_status=0)
begin
/*print '字段: ' + @name*/
set @[email protected]+ ' '[email protected]+ ' like % '[email protected]+ '% '
fetch next from my_cursor into @name
end
/*fetch first from my_cursor into @name*/
/*print @name*/
close my_cursor
deallocate my_cursor
print @SqlStr
------解决方案--------------------
[email protected] 給初值
set @SqlStr = ' '
------解决方案--------------------
declare @SqlStr varchar(1000)
@sqlstr没有赋初始值
应该加上:set @sql= ' '