Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Prioritize values for same column query

$
0
0

Hi all:

SQL08-

I am having a hard time wrapping my head around how to solve this issue. I have some temp tables that are created in a proc from a series of queries that match up a customer to an order they are available to work on. There is a tag column that gives a description of why they were matched for the orderID. Please see attached pic. 

If you look at the tables, notice the same customer may show up for the same order, but with different tags. John Doe for example. He has worked at the facility, and he also worked at an affiliate of the facility, and he also has an active license. But they are all matched for the same order. There are a number of filters I will need to put in, but the one I have a problem with is that I want the customer to be matched to the same orderID only once. Notice the redundancy of John Doe recs - He may have more than one match because he is with two different companies in the temp FacilityMatch table, but he also appears in the other tables. One step in removing the redundancy is that I would like to prioritize the tags. For example, I want John Doe to only show up as "Worked at Facility," since that is the most important tag. The tags should go in this order:

1. Worked at Facility
2.Worked at Affiliate
3.Active License

See the output of query table at the bottom for what I desire. I hope this makes sense because now that I typed it out, it is rather confusing! 


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>