Blog Topics
| Development ( 16 ) |
| DNS ( 17 ) |
| Javascript ( 6 ) |
| Linux ( 8 ) |
| MySQL ( 4 ) |
| Oracle ( 4 ) |
| Perl ( 9 ) |
| PHP ( 6 ) |
| Solaris ( 10 ) |
| Sybase ( 8 ) |
| VitalQIP ( 7 ) |
| Windows Server ( 2 ) |
What's Popular?

| Sybase Case Statement |
|
|
|
| Written by Patrick H. Piper | ||||||||||
|
The Sybase Case statement is handy for performing conditional SQL Expressions. Recently, I needed to summarize the number of static host objects in the VitalQIP database using Sybase. I needed to summarize them by counting how many statically defined objects by: 'A' or Address only records 'PTR' or Reverse PTR only records 'A' and 'PTR' records The easiest way to do that was to use the Sybase Case Statement. The syntax for the Case Statement is as follows: CASE WHEN search_condition THEN expression [WHEN search_condition THEN expression]... [ELSE expression] END CASE AND VALUES syntax: CASE expression WHEN expression THEN expression [WHEN expression THEN expression]... [ELSE expression] END The Case Statement used to get my data looked like this: SELECT COUNT(obj_id), CASE WHEN ns_update_flags = 1 THEN 'A' WHEN ns_update_flags = 2 THEN 'PTR' ELSE 'BOTH' END FROM obj_prof WHERE ns_usage = 1 GROUP BY ns_update_flags When the SQL is executed, the output will look like this:
|
||||||||||
| Last Updated on Tuesday, 26 January 2010 12:13 |










