Results 1 to 11 of 11
  1. #1
    Join Date
    Jan 2004
    Posts
    30

    Unanswered: DECODE in MS SQL

    In Oracle we have expression

    SELECT
    .....
    DECODE (T.LANGUAGE, 'E', T.DESC_ENG, T.DESC)
    FROM
    TABLE T

    if acts like that :
    if T.LANGUAGE = 'E' it returns T.DESC_ENG. If it is different - T.DESC.


    Is there some way to make the same in MS SQL Server ?

  2. #2
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Use a CASE statement.

    blindman
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  3. #3
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    why not just give it to him/her...

    SELECT CASE WHEN T.LANGUAGE = 'E' THEN T.DESC_ENG ELSE T.DESC END

    DECODE is such a pain in the neck...

    I swear Oracle 8i...for as powerful as it is, has NOTHING close to Case...
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  4. #4
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Really? I've heard Oracle people (should we call them "Sibyl"s?) complain many times that SQL Server does not have a DECODE equivalent, but I didn't know that Oracl doesn't have a CASE equivalent. That does seem to be a major shortcoming.
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  5. #5
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Originally posted by blindman
    Really? I've heard Oracle people (should we call them "Sibyl"s?) complain many times that SQL Server does not have a DECODE equivalent, but I didn't know that Oracl doesn't have a CASE equivalent. That does seem to be a major shortcoming.
    I don't know about > 8i...but there is no CASE

    Complain that SQL doesn't have DECODE?

    Looks like 9i has come up to snuff in a lot of areas...

    http://www.praetoriate.com/oracle_ti..._statement.htm
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  6. #6
    Join Date
    Jul 2003
    Location
    San Antonio, TX
    Posts
    3,662
    COALESCE is somewhat similar to DECODE.

  7. #7
    Join Date
    Sep 2003
    Posts
    522
    you can also write your own function to emmulate decode

  8. #8
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Originally posted by rdjabarov
    COALESCE is somewhat similar to DECODE.
    Similar...barely though...as long as you're limited to NULL

    you can also write your own function to emmulate decode
    Really? I was going to give it a shot...but I realized it's not worth it...giving the fact that we already have CASE (which 9i now has).

    You have to have the ability to evaluate ANY expression...I think (and now mind you, only on rare occasions) it would be a big job....
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  9. #9
    Join Date
    Mar 2011
    Posts
    2

    oracle

    Tks, this topic was usefull for me.
    And nowadays oracle have case and decode
    but mssql only have case.

  10. #10
    Join Date
    Jul 2003
    Location
    San Antonio, TX
    Posts
    3,662
    Quote Originally Posted by alcalina View Post
    Tks, this topic was usefull for me.
    And nowadays oracle have case and decode
    but mssql only have case.
    ...and you're only 7 years late...
    "The data in a record depends on the Key to the record, the Whole Key, and
    nothing but the Key, so help me Codd."

  11. #11
    Join Date
    May 2004
    Location
    Seattle
    Posts
    1,313
    late, but at least they brought beer.

Posting Permissions

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