I have a pretty straightforward query that I am essentially hard-coding. I have a table with 3 keys and a description field.
The first key has to do with the type of compensation for an employee (Award
, Hourly
, NonHourly
, Staff
, Other
, and Commission
).
The next key has to do with Payment Frequency. O
refers to One-Time Payment, M
to Multiple Payments.
The third key has to do with the Compensation Rate Code. It's like another frequency. P
means Per Project/Assignment, H
means Hourly, and M
means Monthly.
Certain Employee Compensations types are restricted to different types of compensation. In the below query, I've hard-coded every possibility. Is there a better way to write this query than just hard-coding every combination and unioning them together?
SELECT 'Award'
, 'O'
, 'P'
, 'Per Project or Assignment'
FROM DUAL
UNION
SELECT 'Hourly'
, 'M'
, 'H'
, 'Per Hour'
FROM DUAL
UNION
SELECT 'Hourly'
, 'M'
, 'P'
, 'Per Project or Assignment'
FROM DUAL
UNION
SELECT 'Hourly'
, 'M'
, 'M'
, 'Per Month'
FROM DUAL
UNION
SELECT 'Hourly'
, 'O'
, 'H'
, 'Per Hour'
FROM DUAL
UNION
SELECT 'Hourly'
, 'O'
, 'P'
, 'Per Project/Assignment or Month'
FROM DUAL
UNION
SELECT 'NonHourly'
, 'M'
, 'P'
, 'Per Project or Assignment'
FROM DUAL
UNION
SELECT 'NonHourly'
, 'M'
, 'M'
, 'Per Month'
FROM DUAL
UNION
SELECT 'NonHourly'
, 'O'
, 'P'
, 'Per Project/Assignment or Month'
FROM DUAL
UNION
SELECT 'Staff'
, 'M'
, 'H'
, 'Per Hour'
FROM DUAL
UNION
SELECT 'Staff'
, 'O'
, 'H'
, 'Per Hour'
FROM DUAL
UNION
SELECT 'Other'
, 'M'
, 'H'
, 'Per Hour'
FROM DUAL
UNION
SELECT 'Other'
, 'M'
, 'P'
, 'Per Project or Assignment'
FROM DUAL
UNION
SELECT 'Other'
, 'M'
, 'M'
, 'Per Month'
FROM DUAL
UNION
SELECT 'Other'
, 'O'
, 'H'
, 'Per Hour'
FROM DUAL
UNION
SELECT 'Other'
, 'O'
, 'P'
, 'Per Project or Assignment'
FROM DUAL
UNION
SELECT 'Other'
, 'O'
, 'M'
, 'Per Month'
FROM DUAL
UNION
SELECT 'Commission'
, 'O'
, 'P'
, 'Commission/Tips'
FROM DUAL
Note that DUAL
is just a dummy table. I'm not actually selecting anything from any tables.
EDIT:
This is the SQL behind a View. I wouldn't be opposed to creating new views to "extract" out pieces of the query if that could be used to simplify it. It creates a view that has the following rows in it:
Essentially, my query takes the results of 18 SQL statements and unions them together to get 18 rows in the newly created view. Surely, there's a better way to do it?
The second and third keys are represented in a table that maps their character values to a description (e.g. O -> One-Time Payment). The first key is only used for this view.
SELECT DISTINCT key FROM table
query? \$\endgroup\$SELECT *
that table. \$\endgroup\$AwardDescription
) to your database? \$\endgroup\$