Case study 23: CASE syntax
  • Platform: All
  • Sybase ASE version: 12.5.x and higher
  • Background story: This post is for people ofently looking for Sybase CASE syntax. So, here it is.
  • Task: CASE syntax in short example.
  • Solution: Here is one simple example of CASE usage in SQL.
    First, lets create neccesary objects and data for this example:

    create table TAB
    (ID integer)

    alter table TAB add constraint XPKTAB_ID primary key(ID)

    insert into TAB(ID) values(1)
    insert into TAB(ID) values(2)
    insert into TAB(ID) values(3)
    insert into TAB(ID) values(4)

    In order to see how CASE syntax works, let isssue following command:

    select ID,
           EXPLAIN =
                    when ID = 1 then "YES"
                    when ID = 2 then "NO"
                    else "DO NOT KNOW"
    from TAB

    As a result we will get this:

    ID        EXPLAIN
    1         YES
    2         NO
    3         DO NOT KNOW
    4         DO NOT KNOW

  • Remarks: For detailed explanation and more examples, look at Reference Manual Volume 2: Commands, CASE command.

Locations of visitors to this page
  powered by myself. DBA-Sybase 2006