Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
WelshPunk
Yak Posting Veteran
67 Posts |
Posted - 2008-06-02 : 02:02:33
|
| The 'LIKE' function looks for words that start with whatever is in the like condition. Is there an sql function similar but will look and compare at any part of the search string.For example I am using a webservice in dot net to populate a dropdown list using this sqlSELECT compound_name FROM dbo.compound_name WHERE compound_name like @prefixTextIn this table there is a compound called SILCAP310 and I would like the search function to pick up 310 if I put this into the @prefix parameter. (but I would still like the search to perform like the 'LIKE' does also. SELECT compound_name FROM dbo.compound_name WHERE compound_name like @prefixText or compound_name SearchPartString @prefixTextThanks in advance |
|
|
ranganath
Posting Yak Master
209 Posts |
Posted - 2008-06-02 : 02:30:30
|
| SELECT compound_name FROM dbo.compound_name WHERE compound_name like '%' +@prefixText + '%' |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-06-02 : 02:36:16
|
| May be this:-SELECT compound_name FROM dbo.compound_name WHERE compound_name LIKE '%' + @prefixText + '%' |
 |
|
|
WelshPunk
Yak Posting Veteran
67 Posts |
Posted - 2008-06-02 : 02:37:19
|
| Thank you both. That sorts it out |
 |
|
|
blindman
Master Smack Fu Yak Hacker
2365 Posts |
Posted - 2008-06-02 : 09:44:33
|
| I think you should use visakh's suggestion.While ranganath's code is more concise, being one character shorter, visakh's consistent use of white space improves readability and will make debugging easier.Nice try, though, ranganath. Good effort. ;)e4 d5 xd5 Nf6 |
 |
|
|
|
|
|