Megatest

SQL For Report Format Number 4
Login
Title: All open tickets
Owner: matt
SQL:
SELECT
  CASE WHEN status IN ('Open','Verified') THEN '#f2dcdc'
       WHEN status='Review' THEN '#e8e8e8'
       WHEN status='Fixed' THEN '#cfe8bd'
       WHEN status='Tested' THEN '#bde5d6'
       WHEN status='Deferred' THEN '#cacae5'
       ELSE '#c8c8c8' END AS 'bgcolor',
  substr(tkt_uuid,1,10) AS '#',
  datetime(tkt_mtime) AS 'mtime',
  type,
  status,
  subsystem,
  title,
  comment AS '_comments'
FROM ticket WHERE status IN ('Open')
ORDER BY priority,tkt_mtime ASC
Key:
Active
Review
Fixed
Tested
Deferred
Closed

TICKET Schema

CREATE TABLE ticket(
  -- Do not change any column that begins with tkt_
  tkt_id INTEGER PRIMARY KEY,
  tkt_uuid TEXT UNIQUE,
  tkt_mtime DATE,
  tkt_ctime DATE,
  -- Add as many fields as required below this line
  type TEXT,
  status TEXT,
  subsystem TEXT,
  priority TEXT,
  severity TEXT,
  foundin TEXT,
  private_contact TEXT,
  resolution TEXT,
  title TEXT,
  comment TEXT
)

Notes

Examples

In this example, the first column in the result set is named "bgcolor". The value of this column is not displayed. Instead, it selects the background color of each row based on the TICKET.STATUS field of the database. The color key at the right shows the various color codes.

new or active
review
fixed
tested
defer
closed
SELECT
  CASE WHEN status IN ('new','active') THEN '#f2dcdc'
       WHEN status='review' THEN '#e8e8bd'
       WHEN status='fixed' THEN '#cfe8bd'
       WHEN status='tested' THEN '#bde5d6'
       WHEN status='defer' THEN '#cacae5'
       ELSE '#c8c8c8' END as 'bgcolor',
  tn AS '#',
  type AS 'Type',
  status AS 'Status',
  sdate(origtime) AS 'Created',
  owner AS 'By',
  subsystem AS 'Subsys',
  sdate(changetime) AS 'Changed',
  assignedto AS 'Assigned',
  severity AS 'Svr',
  priority AS 'Pri',
  title AS 'Title'
FROM ticket

To base the background color on the TICKET.PRIORITY or TICKET.SEVERITY fields, substitute the following code for the first column of the query:

1
2
3
4
5
SELECT
  CASE priority WHEN 1 THEN '#f2dcdc'
       WHEN 2 THEN '#e8e8bd'
       WHEN 3 THEN '#cfe8bd'
       WHEN 4 THEN '#cacae5'
       ELSE '#c8c8c8' END as 'bgcolor',
...
FROM ticket

To see the TICKET.DESCRIPTION and TICKET.REMARKS fields, include them as the last two columns of the result set and given them names that begin with an underscore. Like this:

 SELECT
   tn AS '#',
   type AS 'Type',
   status AS 'Status',
   sdate(origtime) AS 'Created',
   owner AS 'By',
   subsystem AS 'Subsys',
   sdate(changetime) AS 'Changed',
   assignedto AS 'Assigned',
   severity AS 'Svr',
   priority AS 'Pri',
   title AS 'Title',
   description AS '_Description',  -- When the column name begins with '_'
   remarks AS '_Remarks'           -- content is rendered as wiki
 FROM ticket