B
B
blainethemono2015-09-09 22:47:53
JavaScript
blainethemono, 2015-09-09 22:47:53

Similar to vlookup in SQL, but with an incomplete match, any ideas?

Hello!
There are 2 tables:
f664665cc2844202b98d73d83641f500.PNG
You need to compare COMPARE with the PHRASE reference column, and if it matches, write ID from Table2 and IF_TRUE from Table1 to a new table. Similar to vlookup from Excel. But the difference is that you need to check the register. In the screenshot, red is false, green is a match.
In theory, there should be hundreds of thousands of such records. Does anyone have any idea how to implement this in T-SQL?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Z
zendor, 2019-04-05
@SergeiB

const n = 12345;
const re = RegExp(`^\\+${n}\\d*$`);

A
Andrey Lastochkin, 2015-09-09
@blainethemono

More or less like this:

SELECT ID, IF_TRUE Result
INTO Table3
FROM Table1
LEFT JOIN Table2
   ON (COMPARE COLLATE SQL_Latin1_General_CP1_CS_AS) LIKE '%' + PHRASE + '%'

I could have confused with the name of the settlement.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question