• facticatech (1/12/2011)


    I have set of columns (more than 10) and need to update them to 0 if it is null.

    for eg: update table set column1=0 where column1 is null

    update table set column2=0 where column2 is null

    ............

    ............

    ............

    update table set column10=0 where column10 is null

    Is there a better way to write in a single statement instead of 10 statements like the one above for 10 different columns?

    hopefully this is what you are looking for

    Update table

    Set col1=isnull(col1,0),

    Col2=isnull(col2,0),

    Col3=isnull(col3,0),

    ….

    ….

    Col10=isnull(col10,0)

    Pramod
    SQL Server DBA | MCSE SQL Server 2012/2014

    in.linkedin.com/in/pramodsingla/
    http://pramodsingla.wordpress.com/