Tuesday, July 28, 2015

Update all of the null values to default values in SQL table

 SELECT  'update '+ so.name+' set '+sc.name+'= '''' where '+sc.name+' is null '  
   
            FROM sysobjects so
            JOIN syscolumns sc ON so.id = sc.id
            JOIN systypes st ON sc.xtype=st.xtype 
            where so.type = 'U'
            and st.name in('nvarchar','int')
            and so.name = 'TableName'

No comments:

Post a Comment