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
 Development Tools
 ASP.NET
 truncating a string

Author  Topic 

simonchia
Starting Member

11 Posts

Posted - 2004-06-16 : 05:44:52
truncating a string
greeting,

I need to get the last value of this string value XXXX.99999.01 which is 01, can anyone help me in this with t-sql? 01 is 2 digit, the digit might grow from 2 to 4.
Thanks in advance for your help.

Nazim
A custom title

1408 Posts

Posted - 2004-06-16 : 07:09:42
declare @mstring varchar(30)
set @mstring='XXXX.99999.01'
select @mstring=reverse(@mstring)
select reverse(substring(@mstring,1,charindex('.',@mstring)-1))


HTH

-------------------------
What lies behind you and what lies ahead of you are small matters compared to what lies within you.-Ralph Waldo Emerson
Go to Top of Page

ehorn
Master Smack Fu Yak Hacker

1632 Posts

Posted - 2004-06-16 : 07:29:09
[code]select parsename('XXXX.99999.01' ,1)[/code]
Go to Top of Page

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2004-06-16 : 09:13:48
try this:

Declare @myVal nvarchar(100)

Set @myVal = 'xxxxxx.999999.01'

Select reverse(left(reverse(@myVal),charindex('.',reverse(@myVal))-1))

Set @myVal = 'xxxxxx.999999.1234'

Select reverse(left(reverse(@myVal),charindex('.',reverse(@myVal))-1))

Set @myVal = 'xxxxxx.999999.65432157'

Select reverse(left(reverse(@myVal),charindex('.',reverse(@myVal))-1))

Corey
Go to Top of Page
   

- Advertisement -