Add a value IF ISNULL

  • Hi,

    I need again your help. Something very easy for you I guess:

    I need to add a value in the column of a table when the value is null.

    So let's say I have table_ads with the columns:

    id country

    1 GB

    2 GB

    3

    4

    5 GB

    I need an SQL query to add the value 'GB' when country IS NULL

    Someone can help me?

    Regards

  • Hi try

    ISNULL(Country,'GB')

    ==========================================================================================================================
    A computer lets you make more mistakes faster than any invention in human history - with the possible exceptions of handguns and tequila. Mitch Ratcliffe

  • ninobuttez (5/14/2013)


    Hi,

    I need again your help. Something very easy for you I guess:

    I need to add a value in the column of a table when the value is null.

    So let's say I have table_ads with the columns:

    id country

    1 GB

    2 GB

    3

    4

    5 GB

    I need an SQL query to add the value 'GB' when country IS NULL

    Someone can help me?

    Regards

    Do you mean you want to update the table or just extract NULL values as 'GB'?

    1. will change value in the table:

    UPDATE table_ads SET country = 'GB' WHERE country IS NULL

    2. just a select:

    SELECT Id, ISNULL(country, 'GB') AS country

    FROM table_ads

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]

  • Thank you and I apologize for my stupid question, but I don't see the table in your query, should I write:

    Select * From tabe_ads ISNULL(Country,'GB');

    ??

  • If it is an update you after it would be something like this:

    Update YourTable

    Set Country = 'GB'

    where Country IS NULL

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • Thank you very much 🙂

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply