I have a question about the possible string match in sql statement, for example I have variable "$val=abc", I can write:

SELECT * FROM table WHERE field like '%$val%'

this will list all recoreds that the field contains sub-string "abc".
Now the question is: if I have a string for example "$val=893abc82", is it possible to "partial match" the field in sql statement and populate the same records? in other words, if the DB field data has the same substring as those from the variable, then list those records? is it possible? thanks for any advice.

michael,


in this case you should write this.

SELECT * FROM table WHERE charindex('abc',field)>0

this should work

thanks,
chaitanya

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.