Avatar of btl2008
btl2008
 asked on

Need view to compare Muliple rows in table 1 to multiple rows in table 2 and give one result

I have two tables. One table contains records where a unique item (x) may associate with several bits. I have another table which assoicates thost bits with a seperate unique code (x'). For example:

tbl1                 tbl2
a 1                  x  1
a 2                  x  2
a 3                  y 1
a 4                  y 2
a 5                  y 3
b 1
b 2
c 1
c 2
c 3
What I'd like to have is a veiw that tells me x is a b because of its combination and y is a c because of its combination, but niether are a because of the required combination. I haven't been able to figure out how to put the view together and I'm hoping it's just a mental margarita on my part. Any ideas?
Microsoft SQL ServerSQL

Avatar of undefined
Last Comment
btl2008

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
chapmandew

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Scott Pletcher

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
chapmandew

That was actually the first time I'd used  checksum_agg
btl2008

ASKER
That's a nifty way of doing it that I haven't seen before. The problem is the actual data in question are all string fields.
btl2008

ASKER
I probably put a bad example in the inital question. Here's a more realistic situation:

tbl1 has multiple Orders. Each Order has mulitple Samples. Each sample has multiple tests defined by a unique three field combination, so a row in table one looks like:

tbl1
Order  Sample     Group     Test   Method
1234   1234-001  Group1  Test1 Method1
1234   1234-001  Group1  Test2 Method1  

tbl2 defines our billing code for combinations of test and method. Some test/methods are grouped together for billing purpose, so we get something like

tbl2
TestCode  Group     Test   Method
A1             Group1  Test1 Method1
A2             Group1  Test1 Method1
A2             Group1  Test2 Method1


In this situation, order 1234 needs to be billed out as 1 A2. The structure of tbl1 is set, but if needed I can change the way tbl2 is set up. Sorry for the confusion. Is this possible?

Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes