Friday, November 23, 2012

Dynamic Stored Procedure for Update

 

Create procedure [dbo].[sp_GenericUpdate]                  
   (  
    @tabName varchar(2000),
    @setCond varchar(2000),
    @whereCond nvarchar(2000)
    )          
As
declare @sql varchar(4000)
if @whereCond <>''
    begin
        select @sql = 'Update '+ @tabName +' Set ' + @setCond  +' Where ' + @whereCond
   
    end
else
    begin
        select @sql = 'Update '+ @tabName +' Set ' + @setCond
    end  
    exec (@sql)  
   

No comments:

Post a Comment