ViKu
ViKu

Reputation: 235

Concatenate parameter of type string with '%' symbol in SQL

I'm trying to match strings in SQL using LIKE.

In my case I'm passing parameter to function of type string (say Ex: myText)

I want to match all the string preceding with myText and ending with any text

Ex: myText='001'

If I have string 001002,001005,0012, it should match all and return values

I'm trying as follows:

SELECT Text
FROM SomeTable
WHERE Text LIKE myText + '%'

Upvotes: 0

Views: 208

Answers (1)

MT0
MT0

Reputation: 168232

The + operator is for the addition of numbers. Text concatenation uses the || operator:

SELECT Text
FROM SomeTable
WHERE Text LIKE myText || '%'

or

SELECT Text
FROM SomeTable
WHERE Text LIKE CONCAT( myText, '%' )

Upvotes: 1

Related Questions