0

The keyword is automatically passed into the query. Suppose the keyword passed is 'Database Manager', now I want to display all results containing 'database'. i.e, it should query the first word of the two-letter keyword. Any help is much appreciated. Thanks. This is my query right now:

$jobQuerySqlStmt .= "
Select * 
  from job 
 WHERE specialization LIKE '$" . $this->paraValues[$std1->JOB_TABLE_SPECIALIZATION] . "%'";

I want the first word of $this->paraValues[$std1->JOB_TABLE_SPECIALIZATION] to be searched for, only.

Strawberry
  • 33,750
  • 13
  • 40
  • 57
  • You would need to split the string (if you just want the first word only). You should be able to do that via SQL or PHP. – Timothy G. May 10 '17 at 18:51
  • 1
    Possible duplicate of [SQL SELECT WHERE field contains words](http://stackoverflow.com/questions/14290857/sql-select-where-field-contains-words) – Ilyes May 10 '17 at 18:52

2 Answers2

0

you might require to add % before and after the $ as below:

$jobQuerySqlStmt .= "
Select * 
 from job 
  WHERE specialization LIKE '%$%" . $this->paraValues[$std1->JOB_TABLE_SPECIALIZATION] . "%'";
Kannan Kandasamy
  • 13,405
  • 3
  • 25
  • 38
0

Sub 'Database Manager' with your variable that has the two word search term:

DECLARE @FirstWord NVARCHAR(MAX)
SET @FirstWord = SUBSTRING('Database Manager', 1, CHARINDEX(' ', 'Database 
Manager'))

Then you query will be like this:

Select * 
  from job 
 WHERE specialization LIKE @FirstWord + '%'
JBdev
  • 353
  • 1
  • 10