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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2002-01-22 : 10:08:58
|
| Aron writes "Hya,I have a table full of prefixes in one field. I need to match a string against that list of prefixes and report if it matches any. Is it possible to do this using the LIKE function or is there any way short of iterating through the entire table?Example:tblPrefixes contains:44551445524455344554Query:Does '4455212345' match any of the prefixes?Thanks, Aron." |
|
|
Nazim
A custom title
1408 Posts |
Posted - 2002-01-22 : 10:38:51
|
| if i have understood your requirements correctly, this should do what you are looking forselect * from tblPrefixes where customerkey like substring('4455212345',1,len(customerkey))--------------------------------------------------------------Dont Tell God how big your Problem is , Tell the Problem how Big your God is |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2002-01-22 : 12:01:23
|
| select * from tblPrefixes where '4455212345' like prefix + '%'select * from tblPrefixes where customerkey like substring('4455212345',1,len(customerkey))doesn't have any wildcards so should be an = instead of like.Be careful of this because there are (or were) bugs in v2000 regarding like without wildcards.==========================================Cursors are useful if you don't know sql.Beer is not cold and it isn't fizzy. |
 |
|
|
arjs
Starting Member
1 Post |
Posted - 2002-01-23 : 04:58:48
|
| I ended up with ... is there anything wrong with this?select *from tblPrefixeswhere CHARINDEX(customerkey, '4455212345') = 1 |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2002-01-23 : 05:39:28
|
| Nope should do the same as the others.==========================================Cursors are useful if you don't know sql.Beer is not cold and it isn't fizzy. |
 |
|
|
|
|
|