I have an awkward problem.
We have a web application that allows outside users to paste a SQL (select only) query into a textbox, click a button, and have the database results displayed on the page.
I have a union query that includes 4 SQL select statements. The query I've created pulls back the exact results I'm looking for, however it requires the user to replace a value in 4 different places. The User_ID value needs to replace '####' with '1234' (or whatever User_ID they are looking up).
What I'd like is a select query where the user only has to replace one value. Because of the security on the web page I can't use a &variable or "set" command because of the security of the web page.
The 4 queries pull back document information from a few different pages depending on if the document still exists, has been transferred, has been purged, or both transferred & purged. There are three main source tables and two lookups:
Existing (same record will not exist in Purged)
Purged (same record will not exist in Existing)
Transferred (will also be in existing until purged)
transfer_lookup is used for looking up transfer_ids related to that user_id
user_lookup is used for looking up doc_ids related to that user_id (non-transfer)
Queries (Trimmed down alot to get the point accross)
SELECT b.user_id, a.doc_id, a.t_date as transferdate, p.pdate as Purged
FROM transfer_lookup b, transferred a, purged p
where a.transfer_id = b.transfer_id
where b.user_id = '####'
and a.doc_id = p.doc_id
Union
SELECT b.user_id, a.doc_id, a.t_date as transferdate,
'Not Purged' as Purged
FROM transfer_lookup b, transferred a, existing e
where a.td_transfer_id = b.transfer_id
and b.user_id = '####'
and a.doc_id = e.doc_id
Union
SELECT u.user_id, e.doc_id, 'N/A' as transferdate, 'Not Purged' as Purged
FROM existing e, user_lookup u
where e.transfer_status = 'N'
and e.user_id = '####'
and e.user_id = u.user_id
Union
SELECT u.user_id, e.doc_id, 'N/A' as transferdate, p.date as Purged
FROM folder_lookup a, purged p, user_lookup u
where p.transfer_status = 'N'
and a.folder = p.folder
and u.user_id = a.user_id
and u.user_id = '####'
So at this point I'm looking at either
* Restructuring my Union query with iff statements (or some other method) to allow the user to change just one value
* Bagging the whole idea because it's too much work.
Any suggestions would be necessary - at the moment I'm leaning towards option B.
-ZE
We have a web application that allows outside users to paste a SQL (select only) query into a textbox, click a button, and have the database results displayed on the page.
I have a union query that includes 4 SQL select statements. The query I've created pulls back the exact results I'm looking for, however it requires the user to replace a value in 4 different places. The User_ID value needs to replace '####' with '1234' (or whatever User_ID they are looking up).
What I'd like is a select query where the user only has to replace one value. Because of the security on the web page I can't use a &variable or "set" command because of the security of the web page.
The 4 queries pull back document information from a few different pages depending on if the document still exists, has been transferred, has been purged, or both transferred & purged. There are three main source tables and two lookups:
Existing (same record will not exist in Purged)
Purged (same record will not exist in Existing)
Transferred (will also be in existing until purged)
transfer_lookup is used for looking up transfer_ids related to that user_id
user_lookup is used for looking up doc_ids related to that user_id (non-transfer)
Queries (Trimmed down alot to get the point accross)
SELECT b.user_id, a.doc_id, a.t_date as transferdate, p.pdate as Purged
FROM transfer_lookup b, transferred a, purged p
where a.transfer_id = b.transfer_id
where b.user_id = '####'
and a.doc_id = p.doc_id
Union
SELECT b.user_id, a.doc_id, a.t_date as transferdate,
'Not Purged' as Purged
FROM transfer_lookup b, transferred a, existing e
where a.td_transfer_id = b.transfer_id
and b.user_id = '####'
and a.doc_id = e.doc_id
Union
SELECT u.user_id, e.doc_id, 'N/A' as transferdate, 'Not Purged' as Purged
FROM existing e, user_lookup u
where e.transfer_status = 'N'
and e.user_id = '####'
and e.user_id = u.user_id
Union
SELECT u.user_id, e.doc_id, 'N/A' as transferdate, p.date as Purged
FROM folder_lookup a, purged p, user_lookup u
where p.transfer_status = 'N'
and a.folder = p.folder
and u.user_id = a.user_id
and u.user_id = '####'
So at this point I'm looking at either
* Restructuring my Union query with iff statements (or some other method) to allow the user to change just one value
* Bagging the whole idea because it's too much work.
Any suggestions would be necessary - at the moment I'm leaning towards option B.
-ZE