Mihail Stoynov's blog!
Surrender your ego
Tuesday, April 29, 2008
Cases in SQL syntax
I've never seen this SQL syntax:
select
column1,
case
when table1.column1 is not null then 1
when
table2.column1
is not null then 2
when
table0.column1
is not null then 0
end as column_nameX,
...
Have you?
Comments [2]
|
Trackback
Tuesday, April 29, 2008 7:21:15 PM UTC
yes, I have
and I use it when appropriate. Your example is not very good but this could be used widely in views to facilitate data understanding. For instance if you have several bit fields for describe why some operation failed you could add calculated column with IF statement of CASE statement to present a better result.
Of course this is not very good in large databases because filtering by this column will cause full table scan
Galcho
Wednesday, April 30, 2008 3:06:19 PM UTC
Yea, it looks like it could get ugly.
I'm wondering why didn't we study it our Database course in the University.
mihail.stoynov
OpenID
Please login with either your
OpenID
above, or your details below.
Name
E-mail
(will show your
gravatar
icon)
Home page
Remember Me
Comment (Some html is allowed:
a@href@title, blockquote@cite, strike
) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.
Enter the code shown (prevents robots):
Live Comment Preview
dasBlog theme by
Mads Kristensen
RSS feed
Search
Archives
November, 2008 (15)
October, 2008 (16)
September, 2008 (30)
August, 2008 (15)
July, 2008 (14)
June, 2008 (26)
May, 2008 (6)
April, 2008 (21)
March, 2008 (14)
February, 2008 (28)
November, 2007 (5)
October, 2007 (7)
September, 2007 (1)
August, 2007 (7)
July, 2007 (3)
June, 2007 (1)
Blog Stats
Total Posts: 203
This Year: 179
This Month: 15
This Week: 2
Comments: 74
Categories
Did you know
Java
rulez
Sucks
БГ
Blogroll
Michael Moore (no rss)
Links
BG-JUG
Copyright policy
No rights reserved.
(You are going to
copy stuff anyway :)
If you mention my
name, thank you.
2008, Mihail Stoynov