HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

Employee Compensations Query

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
compensationsqueryemployee

Problem

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

Solution

This really should be put into a table, if possible.

If such a table already exists, you can take the SELECT for your existing view and simply wrap an INSERT INTO TargetTable statement around it.

INSERT INTO TargetTable
SELECT key1,key2,key3,key4 FROM YourView;
COMMIT;


Otherwise, you can CREATE TABLE TargetTable AS to generate a new table from your return query.

CREATE TABLE TargetTable AS
SELECT key1,key2,key3,key4 FROM YourView;
COMMIT;

Code Snippets

INSERT INTO TargetTable
SELECT key1,key2,key3,key4 FROM YourView;
COMMIT;
CREATE TABLE TargetTable AS
SELECT key1,key2,key3,key4 FROM YourView;
COMMIT;

Context

StackExchange Code Review Q#159458, answer score: 2

Revisions (0)

No revisions yet.