Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
tcwassel
Starting Member
1 Post |
Posted - 2009-08-08 : 20:48:04
|
| Hello, I hope someone may have some suggestions for a SELECT statement I am trying to create.I have a primary table like:Field1 Field2 Field31_____AAA____BBB2_____BBB____AAA1_____CCC____DDD5_____DDD____KKKSecondary table like:Field1 Field2 Field3 Field41__________________X2____BBB____AAA____Y1____CCC___________Z___________________JDesired Result:Field1 Field2 Field3 Field41......AAA....BBB....X2......BBB....AAA....Y1......CCC....DDD....Z5......DDD....KKK....JThe idea here is I want to join to the secondary table based on the maximum number of matching fields. And if there are no matching fields I want to join to the record where field1, field2, and field3 are blank (or null) and field 4 = 'J'. Notice that in the desired result, record 1 selects 'X' because the only match is on Field1 while record 3 selects 'Z' because there is a match on Field1 and Field2.Any help or suggestions is much appreciated. Thanks! |
|
|
|
|
|