SQL question about selecting data from table

Hello,

I’m having a problem in SQL that I’m unable to solve up until now. If I have a table with this data:

[FONT=“Courier New”]-------------
| id | name |

| 1 | abc |
| 2 | abd |
| 3 | def |
| 4 | zxd |
-------------[/FONT]

I want to create a procedure that receives a string as a parameter and returns all the rows in which the “name” column is contained in the parameter string.

For example, calling the procedure like this:

EXEC [Procedure] ‘abxxxxxx’

would return rows 1 and 2 (“ab” is contained in the string ‘abxxxxxx’). Calling the procedure like this:

EXEC [Procedure] ‘abcxxxxxx’

would return only row 1.

Any ideia on how I can do this?

Thanks in advance

Thanks, I’ll test that :slight_smile:

that’s not what prl will need for this problem, it’s actually the other way around

when you do column like ‘%$string%’ you are trying to find $string inside the column

what prl wants is to find the column value inside the given string

so it has to be ‘$string’ LIKE CONCAT(‘%’,name,‘%’)

can you see why?

:slight_smile:

I don’t really understand what you’re trying to say if you’re searching for ‘ab’ in the rows
example: select * from table where column like’%$string%’

going based on the r937 example; the right way is
SELECT CONCAT(columna, columnb) as Whatever FROM table WHERE column like’%$string%’

i don’t really know why you would want to combine columns in SQL command :confused:

use this in your query –

WHERE '$string' LIKE CONCAT('%',name,'%')