本文主要是介绍sql动态游标创建,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
---例子
CREATE PROCEDURE dbo.GetZYFZR@XMBH nvarchar(6),@ZY nvarchar(10)ASdeclare @RETURN nvarchar(2000)declare @TABLERY nvarchar(9)declare @XM nvarchar(20)declare @SQL nvarchar(200)set @RETURN=""set @TABLERY="k"+@XMBH+"RY"--print @TABLERYset @SQL="declare XM_CURSOR cursor for select XM from "+@TABLERY+" where zy='"+@ZY+"' and rylb='03'"exec sp_executesql @SQLopen XM_CURSORfetch next from XM_CURSOR into @XMwhile @@fetch_status=0begin--print @XMselect @RETURN=@RETURN+ltrim(rtrim(@XM))+" "fetch next from XM_CURSOR into @XMendclose XM_CURSORdeallocate XM_CURSORselect ltrim(rtrim(@RETURN))
GO
这篇关于sql动态游标创建的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!