Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2004
    Posts
    162

    Unanswered: return value from another colum

    Hi
    I wonder if its possible to return a value at same row from another colum if col1 contains NULL (or other criteria)

    ex:
    the output is:
    col1,col2,col3
    text1,text10,text100
    text2,text20,text200
    text3,NULL,text300

    Can i take a value from col3 and return it to col2 in the output if a criteria is meet (like NULL)

    the DDL is nvarchar254 at thoose colums.

    thx in advance //Mr

  2. #2
    Join Date
    Jun 2003
    Posts
    269

    Thumbs up

    Code:
    select col1,
    case when col2 is null then col3
    else col2 end as col2,
    col3 from (select 'r' col1,null as col2,'j' col3) as tm
    I love cursor,though I never use it.Cos' I dont want to misuse it.
    ----------------------------------------------

    ----cheers
    ----http://mallier.blogspot.com

  3. #3
    Join Date
    Mar 2004
    Posts
    162
    works just great, thx alot....

    /Mr

  4. #4
    Join Date
    Dec 2002
    Posts
    1,245
    Quote Originally Posted by mallier
    Code:
    select col1,
    case when col2 is null then col3
    else col2 end as col2,
    col3 from (select 'r' col1,null as col2,'j' col3) as tm
    Um....

    IsNull(Col2, Col3)

    or...

    Coalesce(Col2, Col3)
    Have you hugged your backup today?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •