I need help on T-SQL. I have a stored procedure in my SQL Server with query (sample) as below:
Select empid, empname, sal from emp
where empname like '%jo%'
and empname like '%el%'
Let’s say, the above query returns records as shown below:
empid empname sal
17 john $1000
45 elena $2000
I need to have another column to the above select statement which should say 'jo' for %jo% record and 'el' for %el% record. For example:
empid empname sal SearchString
17 john $1000 jo
45 elena $2000 el
Is this possible?
Thank you
To cater for multiple conditions you can make use of a
CTESQL Statement
Test script