Reputation: 139
Is there a way i can run a partial match for two SQL columns: I have two SQL columns as given below. Column01 is Integer and Column 02 is string.
Column01 Column02
125 Length of room is 125 meter only
I am interested to run a partial match and see if the values are Column01 are available in the Column two or not. I have attempted this below coding but it's definitely not working
Where Column02 like '%' + Column01 + '%'
This syntax does runs a partial match but it pulls the results like %Column01% (working as a concatenate function).
Is there a solution to this issue?
Thanks in anticipation
Upvotes: 1
Views: 1433
Reputation: 1271141
If your concern is delimiters (so you don't want 125 to match 1250), then you can do something like this:
Where ' ' + Column02 + ' ' like '% ' + Column01 + ' %'
Upvotes: 0
Reputation: 122042
DECLARE @t TABLE
(
Column01 VARCHAR(20),
Column02 VARCHAR(100)
)
INSERT INTO @t (Column01, Column02)
VALUES ('125', 'Length of room is 125 meter only')
SELECT *
FROM @t
WHERE CHARINDEX(Column01, Column02) > 0
Upvotes: 1