DB Query - filter for LIKE value

I am struggling to filter for rows in DB query.

SELECT * FROM #table# AS “table”
where “Coding” LIKE ‘%’ + ‘.’ + “Type”

I have the following table:

Type| Coding
M01|ABC.0.0.0.M89
M02|ABC.0.0.0.M10
M03|ABC.0.0.0.M03
M02|ABC.0.0.0.M02
M03|ABC.0.0.0.P12
T03|ABC.0.0.8980.P12

Output:
M03|ABC.0.0.0.M03
M02|ABC.0.0.0.M02

Thank you

It is not clear what database you use.
Anyway, you can do it like this using T-sql
SELECT Type, Coding
FROM #table#
where Type = right(Coding,3)

Hi @Rokank , as @izaychik63 mentions, providing syntax without knowing the database is difficult.

A couple of things.

Firstly… Presumably you have selected the required table in a DB Table Selector first? :slight_smile:

image

Secondly, ANSI standard (but not necessarily followed by your particular db vendor) for string concatenation is a pair of pipe symbols:

SELECT * FROM #table# AS "table"
WHERE "Coding" LIKE '%' || '.' || "Type"

Another ANSI standard but (differently) followed by vendors is the concat( ) function

SELECT * FROM #table# AS "table"
WHERE "Coding" LIKE concat('%' , '.' , "Type")

but notably some vendors (e.g Oracle) haven’t implemented this to allow more than 2 strings

and then there is SQL Server with the + syntax that you have tried.

There is no one concatenation method that works exactly the same way across all SQL databases.

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.