954,593 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Question about SQL statement

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.

michael123
Junior Poster in Training
94 posts since Jun 2005
Reputation Points: 10
Solved Threads: 0
 

michael,


in this case you should write this.

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

this should work

thanks,
chaitanya

chmonalisa
Light Poster
26 posts since Sep 2006
Reputation Points: 11
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You