3 Replies - 203 Views - Last Post: 10 July 2014 - 09:41 AM Rate Topic: -----

#1 Dnamonk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 15-June 14

problems with LIKE statement

Posted 10 July 2014 - 09:30 AM

Hello everybody,

I have a requirement where I should use the value of table id and search it against another field:
So I was trying with LIKE or REGEXP but nothing is working :

Below is my query:

select name,street,shop from mtTABLE where Details REGEXP  '%convert(id AS char)%';



but the result is coming a s zero !

Does somebody knows howto get around with this ?

Thanks in advance

Is This A Good Question/Topic? 0
  • +

Replies To: problems with LIKE statement

#2 Dnamonk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 15-June 14

Re: problems with LIKE statement

Posted 10 July 2014 - 09:31 AM

Hello everybody,

I have a requirement where I should use the value of table id and search it against another field:
So I was trying with LIKE or REGEXP but nothing is working :

Below is my query:

select name,street,shop from mtTABLE where Details LIKE  '%convert(id AS char)%';



but the result is coming a s zero !

Does somebody knows howto get around with this ?

Thanks in advance
Was This Post Helpful? 0
  • +
  • -

#3 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9363
  • View blog
  • Posts: 35,172
  • Joined: 12-June 08

Re: problems with LIKE statement

Posted 10 July 2014 - 09:38 AM

What does 'like' do?

Quote

Determines whether a specific character string matches a specified pattern.

http://msdn.microsof...y/ms179859.aspx



Here you are asking if the value of 'details' has the string "convert(id AS char)"in it somewhere with what ever characters before - or after - it. String comparison.
Details LIKE  '%convert(id AS char)%';


Perhaps use some sort of string append option like:
Details LIKE  '%' + convert(id AS char) + '%'

Was This Post Helpful? 1
  • +
  • -

#4 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3549
  • View blog
  • Posts: 10,317
  • Joined: 08-June 10

Re: problems with LIKE statement

Posted 10 July 2014 - 09:41 AM

itís not working because itís a string, not a function. and besides that it probably wouldnít work either because id in the convert() function is not specified, when the function is executed, the parameter must contain a single value, not all values.

other than that, what does "use the value of table id and search it against another field" mean? I cannot think of a context where that sentence would make sense.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1