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
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:
when ID = 1 then "YES"
when ID = 2 then "NO"
else "DO NOT KNOW"
As a result we will get this:
3 DO NOT KNOW
4 DO NOT KNOW
- Remarks: For detailed explanation and more examples, look at Reference Manual Volume 2: Commands, CASE command.