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

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

Break comma separated into multiple rows in MYSQL

mysql global search procedure