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)
 Substring / String?

Author  Topic 

JimL
SQL Slinging Yak Ranger

1537 Posts

Posted - 2004-03-31 : 12:14:20
I have to Extract a numaric value from the center of a string in a SP.
The Extract is always precided by a single Alpha and followed by 2 Alpha .

Example

String Extract result
R3343KL 3343
R331JL127 331
C12BS19 12
I23976AL 23976

Any Ideas.

Jim
Users <> Logic

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2004-03-31 : 12:27:22
Hi Jim --

Try something like this:


declare @v varchar(100);

set @v = 'A12444B'

select substring(@v, 2, patindex('%[A-Z]',substring(@v,2,100))-1)

there's a few other ways, but that's one ....

- Jeff
Go to Top of Page

JimL
SQL Slinging Yak Ranger

1537 Posts

Posted - 2004-03-31 : 12:49:45
Thanks Jeff I forgot all About pattern Index.

Jim
Users <> Logic
Go to Top of Page
   

- Advertisement -