当前位置: 代码迷 >> Sql Server >> 没有这种语法吗?该如何处理
  详细解决方案

没有这种语法吗?该如何处理

热度:58   发布时间:2016-04-27 19:48:15.0
没有这种语法吗?
create   procedure   procTest1
        @field_name   nvarchar(20),
        @value   nvarchar(20),
        @where_name   nvarchar(20),
        @tbl_name   nvarchar(30),
        @curOut   cursor   varying   output
as  
        declare   @str   varchar(1000)
        select   @str= 'select   '[email protected]_name+ '   from   '[email protected]_name+
                                                          '   where   '[email protected]_name+ '= '[email protected]
        set   @curOut=cursor   for   @str
        open   @curOut
go

--我想返回一个游标.而我又想用动态Sql.怎么写?

------解决方案--------------------
/*
怎么可能不行
*/

create procedure procTest1
@field_name nvarchar(20)= 'name ',
@value nvarchar(20)=1,
@where_name nvarchar(20)= 'id ',
@tbl_name nvarchar(30)= 'sysobjects ',
@curOut cursor varying output
as
--declare @str varchar(1000)
declare @str nvarchar(2000)
--select @str= 'select '[email protected]_name+ ' from '[email protected]_name+ ' where '[email protected]_name+ '= '[email protected]
select @str=N 'set @curOut = cursor for select '[email protected]_name+N ' from '[email protected]_name+N ' where '[email protected]_name+N '= '[email protected]+char(10)+N 'open @curOut '
exec sp_executesql @str, N '@curOut cursor output ', @curOut output
--set @curOut=cursor for @str
--open @curOut
go


declare @curOut cursor
exec procTest1 @[email protected] output
fetch next from @curOut
close @curOut
deallocate @curOut
/*
name
---------
sysobjects
*/

drop procedure procTest1
  相关解决方案