[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 303
  • 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

Featured Post

Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

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