Using Cast.

  • I have a table and it has a column called Memo. Some rows in this table have text in memo column, some have null, and some are empty string. I would like to add an extra column to this table and insert yes, if there is "YES" in the memo column if there is text, and "NO" if there is no text or it is null. How do I do this. Do I use cast?! Thanks

    select *, cast () as newColumn

    from myTable

  • SELECT ...

    ,CASE WHEN COALESCE(Memo, '') = ''

    THEN 'NO'

    ELSE 'YES'

    END

    FROM yourtable;

    Jeffrey Williams
    “We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”

    ― Charles R. Swindoll

    How to post questions to get better answers faster
    Managing Transaction Logs

  • Thanks a lot!

  • Can I ask why you're doing this?

    Is this a one-time y/n determination (in which case, why add a new column, just check as previous poster showed whether something exists) or is this something that you want to keep updated going forward? (in which case I assume you're creating a trigger that will update your column if someone adds text to the memo?)

    Just curious.

    ---------------------------------------------------------
    How best to post your question[/url]
    How to post performance problems[/url]
    Tally Table:What it is and how it replaces a loop[/url]

    "stewsterl 80804 (10/16/2009)I guess when you stop and try to understand the solution provided you not only learn, but save yourself some headaches when you need to make any slight changes."

Viewing 4 posts - 1 through 3 (of 3 total)

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