The Power of SQL CASE Statements

November 3, 2004

[From 4GuysFromRolla.com]

Introduction
As developers creating data-driven Web applications, we've all written more than our fair share of SQL statements. If I had a nickel for every SELECT statement or UPDATE statement I've written in my six years as a Web developer, I'd be a rich man. Despite the familiarity with SQL that many Web developers have, one of the lesser known SQL tools is the CASE statement. The CASE statement is a wily little fellow that can be added to both the SELECT portion of a SELECT statement as well as the ORDER BY portion. With CASE you can easily group data into various ranges, you can beautify the results of a SQL query, and can allow for dynamic sorting of the query's results. CASE statements can also be used to give subtitles to ROLLUP and CUBE queries, and can be used in computed columns to boot.

In this article we'll take a look at the powerful CASE statement, shining light on its utility and usefulness in everyday data-driven Web sites. Read on to learn more!

The article continues at http://www.4guysfromrolla.com/webtech/102704-1.shtml








The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers