• Sean Lange (9/16/2013)


    SteveEClarke (9/16/2013)


    Okay -

    So I have a basic table - 100 Columns - ALL VALUES, when populated, there are NULL values entered instead of 0 ( zero ).

    So want to scan the fields and replace NULL with 0 (zero)

    update BasicTable

    for count = 1 to maximumnumberoffields

    if fieldname[count] is null

    set fieldname[count] = 0

    endif

    next

    something like that !?

    No. You will have to either code a big long list or use dynamic sql for this. You could use some dmvs to help build your dynamic sql.

    See if this might help get you started. All you would need to do is add the UPDATE TableName and any where predicates. This would build all the column updates for you.

    select sc.name + ' = isnull([' + sc.name + '], 0), '

    from sys.objects so

    join sys.columns sc on so.object_id = sc.object_id

    where so.name = 'YourTableNameHere'

    --and any other filters needed

    I apologize, I should've hit quote instead of reply