prl
July 2, 2010, 6:01pm
1
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
r937
July 3, 2010, 11:20pm
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?
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
July 2, 2010, 7:17pm
5
use this in your query –
WHERE '$string' LIKE CONCAT('%',name,'%')