Requisite snarky comment: if a join depends on only _part_ of the value of another field, the data is not normalized.
Are the DeptNum fields really literally question marks and digits, as if they were wildcards?
If so, you could write some UDF to convert DOS wildcards of * and? to SQL wildcards of % and _
It's a bit unholy but it ought to get the job done:
SELECT Employee.*, Dept.* from Employee JOIN Dept ON Employee.Dept LIKE MyUDF(Dept.DeptNum)
On Tue, Jul 2, 2019 at 12:57 PM Paul H. Tarver paul@tpcqpc.com wrote:
Ok, I need a little help and here's the scenario:
I have an x-ref table that looks like this:
DeptNum, Description, Value
1??, Dept 1, 99930
2??, Dept 2, 92382
3??, Dept 3, 83728
?4?, Dept 4, 27377
Next, I have a data table with thousands of employees with department numbers I want to scan through. If the employee's dept # is 101, then in the fastest way possible, I want to compare 101 to the DeptNum in the x-ref table and return the value 99930. If the employee's dept # is 141, then the search should return both 99930 and 27377 and I'll perform some logic to determine which value is most important.
I know I can do SELECT queries using the LIKE statement such as Select * from x-ref where x-ref.DeptNum LIKE "1%", but in this case, I know the explicit value and I need to compare it to the masked values in the x-ref table. So I really need to the reverse which would be Select * from x-ref where "1%" LIKE x-ref.DeptNum (which doesn' t work, I know.). FYI, The DeptNum field can be up to 20 characters long and I am guessing the masked values could be as well.
Unfortunately, I think I'm stuck mentally on doing this with a SQL Query and I'm not able to think outside of this box right now, so any suggestions will help. Hell, at this point, I'll take snarky comments, but only if they contain clues to how I need to proceed. LOL
Thanks in advance
Paul H. Tarver
--- StripMime Report -- processed MIME parts --- multipart/alternative text/plain (text body -- kept) text/html
[excessive quoting removed by server]