Suppose there are 2 tables with data as shown below:
-- Table
I want to select data from two JOINed tables in dbo.FUNCTION_Match (TelNO, Expression) . ( dbo.FUNCTION_Match is a crude function that wroted matches TelNO and Expression . In this example, you can think of it as TelNO LIKE Expression ).
So the result of SQL and query
SELECT * FROM #Detail d LEFT JOIN #FeeRate f ON d.TelNO LIKE f.Expression TelNO Expression Price Description ---------- ---------- ------- -------------------------------------------------- 001xxxxx 001% 10.00 International call 020xxxxx 0[^0]% 5.00 National call 021xxxxx 0[^0]% 5.00 National call 800xxxxx 800% .00 Free call 400xxxxx 400% .80 800 like, but caller need pay for local part 28011111 NULL NULL NULL 82188888 NULL NULL NULL 22223333 NULL NULL NULL
The problem is obvious, local calls in #Detail cannot match Others FeeRate.
My crude FUNCTION_Match function processed several expressions like TelNO NOT LIKE '0%' AND TelNO NOT LIKE [84]00% OR TelNO LIKE '0755%' to match Others FeeRate, but it's hard to write the correct multiscreen expression to express ELSE when in the table #FeeRate has a lot of entries.
So, is there a way to implement an ELSE expression from data?
SQL to create sample data
CREATE TABLE
source share