Analyst2004
Technical User
I take 4 pair of inputs from user in a SQL query with '&Variable'. The input is part of DECODE statement(in the Where -Clause) and it pulls the data from the Table as per the DECODE condition.
However, my result set is not in the order of the user-input. I want to sort it as per the data user provided while executing the query.
SELECT *
FROM XYZ
WHERE
field1 = DECODE(( SELECT COUNT(*) FROM XYZ A WHERE EXISTS (SELECT filed1 FROM XYZ B
WHERE field1 = '&n1' )),0,'&a1','&&n1')
OR
field1 = DECODE(( SELECT COUNT(*) FROM XYZ A WHERE EXISTS (SELECT filed1 FROM XYZ B
WHERE field1 = '&m' )),0,'&b','&&m')
I am running this in TOAD.
Any Clues on How to get it in ORDER BY as per user input ?
However, my result set is not in the order of the user-input. I want to sort it as per the data user provided while executing the query.
SELECT *
FROM XYZ
WHERE
field1 = DECODE(( SELECT COUNT(*) FROM XYZ A WHERE EXISTS (SELECT filed1 FROM XYZ B
WHERE field1 = '&n1' )),0,'&a1','&&n1')
OR
field1 = DECODE(( SELECT COUNT(*) FROM XYZ A WHERE EXISTS (SELECT filed1 FROM XYZ B
WHERE field1 = '&m' )),0,'&b','&&m')
I am running this in TOAD.
Any Clues on How to get it in ORDER BY as per user input ?