USE [chss_back]
GO
/****** 对象: StoredProcedure [dbo].[sp_Public_PyWbmGet] 脚本日期: 07/28/2015 10:54:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE procedure [dbo].[sp_Public_PyWbmGet] 
@tablename varchar(32), 
@fieldname1 varchar(32), 
@fieldname2 varchar(32), 
@pybz char(1) = '0' 
as 
set nocount on exec('declare @name varchar(255),@shortcut varchar(255)'+ 
' declare cs_py cursor for select '+@fieldname1+','+@fieldname2+ 
' from '+@tablename+ 
' where '+@fieldname2+ ' is null'+
' for update of '+@fieldname2+ 
' open cs_py'+ 
' fetch cs_py into @name,@shortcut'+ 
' while @@fetch_status=0'+ 
' begin exec sp_Public_PyWbm @name,'+@pybz+',@shortcut output'+ 
' update '+@tablename+' set '+@fieldname2+'=convert(varchar(40),@shortcut)'+ 
' where current of cs_py'+ 
' fetch cs_py into @name,@shortcut end'+ 
' close cs_py deallocate cs_py' 
)
GO