We help IT Professionals succeed at work.

Separate query list

Allen Pitts
Allen Pitts asked
on
Medium Priority
313 Views
Last Modified: 2012-08-14
Good afternoon expert,

A query has been written and works. Would like the procedures returned by the first
two qualifiers (the two that end in 59618') and 74%') to be listed before the procedures returned by the second two qualifiers (the two that end in 59614') and 73%'))

Can that be done?

Thanks.

Allen in Dallas


select * from PXC_Procedure_code where
(PXC_TYPE = 'CPT' and PXC_CODE in ('59510', '59618')
OR
PXC_TYPE = 'ICD9' and PXC_CODE like '74%')
OR
(PXC_TYPE = 'CPT' and PXC_CODE in ('59400', '59409', '59410', '59610', '59612', '59614')
OR
PXC_TYPE = 'ICD9' and (PXC_CODE like '72%' or  PXC_CODE like '73%'))
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2012
Distinguished Expert 2019
Commented:
Can you not do an order by?

To come up with the exact syntax, I think we need more data.

Can you show the results of the following query then what you want?

select PXC_TYPE, PXC_CODE from PXC_Procedure_code where
(PXC_TYPE = 'CPT' and PXC_CODE in ('59510', '59618')
OR
PXC_TYPE = 'ICD9' and PXC_CODE like '74%')
OR
(PXC_TYPE = 'CPT' and PXC_CODE in ('59400', '59409', '59410', '59610', '59612', '59614')
OR
PXC_TYPE = 'ICD9' and (PXC_CODE like '72%' or  PXC_CODE like '73%'))

You might need to add an outer query and a dummy sort column with a case statement.  You can add the rest of the logic.

Something like:

select PXC_TYPE, PXC_CODE from
(
select PXC_TYPE, PXC_CODE, case when PXC_TYPE='CPT' and  PXC_CODE in ('59510', '59618') then 0 else 1 end sort_order from PXC_Procedure_code where
(PXC_TYPE = 'CPT' and PXC_CODE in ('59510', '59618')
OR
PXC_TYPE = 'ICD9' and PXC_CODE like '74%')
OR
(PXC_TYPE = 'CPT' and PXC_CODE in ('59400', '59409', '59410', '59610', '59612', '59614')
OR
PXC_TYPE = 'ICD9' and (PXC_CODE like '72%' or  PXC_CODE like '73%'))
) order by sort_order

Explore More ContentExplore courses, solutions, and other research materials related to this topic.