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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Search String

Author  Topic 

pcmech
Starting Member

7 Posts

Posted - 2003-02-11 : 11:19:06
I have an extensive search page that creates a ‘sql where’ clause that is then run dynamically by a stored procedure to produce the search results.

What I am having problems with is in searching one of the fields (lets call it keycode). The database has approx. 250,000 records and each keycode field has a unique string. This string contains codes that determine the records origin etc. I need to search this field for specific values in positions 7, 8 & 9. The users will then have a choice of selecting an appropriate field for each of these positions (remember each field does have the option of ‘all records’ (%) )

For example:

Data in table-
1234567890abcdefg
2234567890abcdefg
3234567c90abcdefg
4234567d90abcdefg

Need to Search positions 7, 8 and 9 for-
789

Would return-
1234567890abcdefg
2234567890abcdefg

Or Search positions 7, 8 and 9 for-
7d9

Would return-
4234567d90abcdefg

I have tried using this - (Right(KeyCode, 9) Like ‘%789’) - but what this doesn’t take into account is the possibility of a search string like ‘%7%9’ or ‘%7%%’ etc. (these would not search the specific positions of 7, 8 and 9.

Any ideas on how this might be accomplished?

Thanks in advance


lane0618
Posting Yak Master

134 Posts

Posted - 2003-02-11 : 14:04:16
try:

substring(keycode,7,3)

in your where clause.

Lane



Edited by - lane0618 on 02/11/2003 14:05:17
Go to Top of Page
   

- Advertisement -