|
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)
go
alter table TAB add constraint XPKTAB_ID primary key(ID)
go
insert into TAB(ID) values(1)
insert into TAB(ID) values(2)
insert into TAB(ID) values(3)
insert into TAB(ID) values(4)
commit
go
In order to see how CASE syntax works, let isssue following command:
select ID,
EXPLAIN =
case
when ID = 1 then "YES"
when ID = 2 then "NO"
else "DO NOT KNOW"
end
from TAB
go
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.
|
|
|