Home » Other » Client Tools » DEFINE VARIABLES and AMPERSAND (ORACLE DB SQL)
DEFINE VARIABLES and AMPERSAND [message #608041] |
Fri, 14 February 2014 08:38 |
|
hans_cellc
Messages: 11 Registered: February 2014
|
Junior Member |
|
|
Please assist.
Below is my code for sql.
Second code does not work, just curious from a programming point of view WHY?
Is my coding wrong or is there another way.
-- DECODE
SELECT last_name, salary,
DECODE(TRUNC(salary / 2000, 0),
0, 0.00,
1, 0.09,
2, 0.20,
3, 0.30,
4, 0.40,
5, 0.42,
6, 0.44,
0.45) AS "Tax Rate"
FROM employees
WHERE department_id = 80;
-- DECODE with variables _____________________NOT WORKING
DEFINE tax_rate = (DECODE (TRUNC(salary / 2000, 0),
0, 0.00,
1, 0.09,
2, 0.20,
3, 0.30,
4, 0.40,
5, 0.42,
6, 0.44,
0.45))
SELECT last_name, salary, &tax_rate AS "Tax Rate"
FROM employees
WHERE department_id = 80
ORDER BY &tax_rate;
|
|
|
|
|
|
|
Re: DEFINE VARIABLES and AMPERSAND [message #608052 is a reply to message #608048] |
Fri, 14 February 2014 09:19 |
cookiemonster
Messages: 13961 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
This should work:
DEFINE tax_rate = ' (DECODE (TRUNC(salary / 2000, 0), 0, 0.00, 1, 0.09, 2, 0.20, 3, 0.30, 4, 0.40, 5, 0.42, 6, 0.44, 0.45)) '
SELECT last_name, salary, &tax_rate AS "Tax Rate"
FROM employees
WHERE department_id = 80
ORDER BY &tax_rate;
define has to be on a single line and it needed quotes.
|
|
|
|
Goto Forum:
Current Time: Thu Jan 02 16:15:01 CST 2025
|