Formatting and Displaying Data

The way you store data isn't always the best way to display it. If you have application programs such as report generators connected to your database, they may provide all the formatting that you need. Sometimes, however, it makes sense to use the string, number, and date functions that most database vendors support. Many of them became part of the ANSI SQL standard in 1992.

But remember: SQL is not a display tool! It was designed to retrieve data, not to make it look good. If some of the recipes in this section look convoluted, it's because they are.

This section includes code for

  • Displaying one column as two;

  • Displaying two columns as one; and

  • Converting data from one datatype to another;

Get Practical SQL Handbook, The: Using SQL Variants, Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.