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)
 Verifying a text string falling within a text string range

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-04-10 : 08:50:35
Felix writes "I am thinking how I can verify a text string falls within a text string range.

For example, I have a table containing two fields. One is the Lower sequence and another one is the Upper sequence. I make up some of the data (The pattern and the length of the string doesn't have to be this way).

Lower Upper
1000AA01 1000AZ99
1000BA01 1000BZ99
. .
. .
1234AA01 1234AZ99
. .
3456AA01 5678AZ99

I would like to verify a text string "1234AB45" falling within the range of 1234AA01 and 1234AZ99. How can I do it? Thank you."

setbasedisthetruepath
Used SQL Salesman

992 Posts

Posted - 2002-04-10 : 09:18:43
Actually it's not as hard as it might look; SQL Server can do the string comparison natively without any extra work from you. Here's an example:

declare @x char(5), @y char(5), @z char(5)
set @x = '123b5'
set @y = '123z5'
set @z = '123g6'

if @z between @x and @y
print 'yes'
else
print 'no'

setBasedIsTheTruepath
<O>
Go to Top of Page
   

- Advertisement -