Dynamic SQL to Apply IsNULL on All Columns of a table

Dynamic SQL to Apply IsNULL on All Columns of a table according to data type.





SELECT 
'isnull('+COLUMN_NAME+',' +CASE WHEN  DATA_TYPE ='varchar' THEN ''''')' WHEN  DATA_TYPE ='datetime' THEN 'getdate())' ELSE '0)' END
,*
FROM INFORMATION_SCHEMA.columns WHERE TABLE_NAME='Property' AND IS_NULLABLE='NO'

Comments

Popular posts from this blog

Grouping Sets, With Rollup and With Cube example

Adding Page brake aganist group values

To Get All the Names of tables and Databases their data have changed in last 24 Hours And Backup those databases