IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_update_table_null_field]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_update_table_null_field]
GO
create proc [dbo].[mps_update_table_null_field](
@tabname varchar(100)
)
as
begin

declare @sql varchar(max) = ''

set @sql =
N'
declare @sql varchar(max)=''''

select @sql= @sql+char(10)+
        ''update ''+ o.name+
        '' set '' +c.name +'' =  case ''''''+ tp.name+'''''' when ''''int'''' then 0 '' +
 '' when ''''bigint'''' then  0 '' +
 '' when ''''ntext'''' then '''''''''' +
 '' when ''''text'''' then '''''''''' +
 '' when ''''nvarchar'''' then '''''''''' +
 '' when ''''varchar'''' then '''''''''' +
 '' when ''''datetime'''' then '''''''''' +
 '' when ''''decimal'''' then 0 ''  +
 '' else 0 end where  '' +c.name +'' is null  ''     
    from
        sys.columns c
        join sys.types tp on c.user_type_id = tp.user_type_id
        left join sys.computed_columns cc on c.object_id = cc.object_id and c.column_id = cc.column_id
        left join sys.default_constraints dc on
            c.default_object_id != 0
            and c.object_id = dc.parent_object_id
            and c.column_id = dc.parent_column_id
        left join sys.identity_columns ic on c.is_identity = 1 and c.object_id = ic.object_id and c.column_id = ic.column_id
        left join sys.objects o on o.object_id = c.object_id 
    where o.name = '''+@tabname+''' and isnull(ic.is_identity,0) !=1 '    
    +' order by
        ic.is_identity desc,
        c.name
    print @sql
    execute(@sql)   
    '
    print @sql 
  execute(@sql)
        
end