prl — 2010-07-02T14:01:45-04:00 — #1
I'm having a problem in SQL that I'm unable to solve up until now. If I have a table with this data:
| id | name |
| 1 | abc |
| 2 | abd |
| 3 | def |
| 4 | zxd |
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
prl — 2010-07-05T05:45:55-04:00 — #2
Thanks, I'll test that
r937 — 2010-07-03T19:20:17-04:00 — #3
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?
shaydez — 2010-07-03T17:07:04-04:00 — #4
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 :/
r937 — 2010-07-02T15:17:25-04:00 — #5
use this in your query --
WHERE '$string' LIKE CONCAT('%',name,'%')