Subject SELECT with ORDER BY
Author Bill Oliver
Hi all!

I have this huge query (which works!)

select distinct alert.alert_id, alert.primary_entity_name,
alert.primary_entity_level_code,
alert_description, alert.run_date, alert.create_date,
alert.alert_risk_score, S.scenario_name, alert.alert_status_code,
alert.user_id, alert.actual_values_text, S.SCENARIO_CATEGORY_DESC,
alert.primary_entity_number, alert.scenario_id,
alert.primary_entity_key,
alert.group_id, usr.display_name
from fsk_alert alert, fsk_group_user group_user, fsk_scenario S,
fsk_user usr
where (group_user.group_id = alert.group_id or group_user.user_id =
alert.user_id)
and group_user.user_id in (-2)
and alert.user_id != 100
and alert.logical_delete_ind = 'N'
and alert.alert_status_code = 'ACT'
and alert.scenario_id = S.scenario_id
and alert.user_id = usr.user_id
union select distinct alert.alert_id, alert.primary_entity_name,
alert.primary_entity_level_code, alert.alert_description,
alert.run_date, alert.create_date, alert.alert_risk_score,
S.scenario_name, alert.alert_status_code,alert.user_id,
alert.actual_values_text, S.SCENARIO_CATEGORY_DESC,
alert.primary_entity_number, alert.scenario_id,
alert.primary_entity_key, alert.group_id, usr.display_name from
fsk_alert alert, fsk_group_user group_user, fsk_scenario S, fsk_user
usr where group_user.group_id = alert.group_id and
alert.logical_delete_ind = 'N'and alert.alert_status_code = 'ACT' and
group_user.user_id != alert.user_id and alert.scenario_id =
S.scenario_id and group_user.user_id = 100 and alert.user_id =
usr.user_id
order by 7 desc


I would really like to use the column name in the ORDER BY clause, as
in "ORDER BY alert_risk_score DESC" but no luck. I've tried
FSK_ALERT.alert_risk_score, ALERT.alert_risk_score, and tried quoting
the column name, but nothing seems to work.

Normally this wouldn't be such a big deal, but this is generated
code, and I won't be able to easily modify the query.

-b