• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 305
  • Last Modified:

Separate query list

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%'))
0
Allen Pitts
Asked:
Allen Pitts
1 Solution
 
slightwv (䄆 Netminder) 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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now