Skip to end of banner
Go to start of banner

How to use SQL case statement to improve visual appeal

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Current »

Description

Most databases support some flavor of the SQL case statement making it easy to condition what appears in a column. This will show how to combine this with Confluence capabilities like macros to improve how information is displayed.

Example Using Emoticons

This example uses emoticons to visually indicate some aspect of the data this is import to highlight to the viewers.

  • Use a standard sql-query macro accessing your data source containing the data you want to query.
  • Use wiki for the Output format parameter.
  • The SQL will use a case statement. This example uses Postgres, but other database will be similar. Consult your database documentation's case statement for more details.

 

SQL
select 
     "Product",
     "Plan",     
     "Revenue",
     case 
         when "Revenue" >= "Plan" then '(/)'
         else '(x)'
     end as "Met Plan"
 from products

 

 

Example Using Macros

This example uses a Confluence macro to add visual indicators to the display.

  • Use a standard sql-query macro accessing your data source containing the data you want to query.
  • Use wiki for the Output format parameter.
  • The SQL will use a case statement. This example uses Postgres, but other database will be similar. Consult your database documentation's case statement for more details.

 

SQL
select 
     "Product",
     "Plan",      
     case 
         when "Revenue" >= "Plan" then '{color:green}*' || "Revenue" || '*{color}'
         else '{color:red}*' || "Revenue" || '*{color}'
     end as "Revenue"
 from products



 

  • No labels