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)
 strip charactors from the right

Author  Topic 

cidr
Posting Yak Master

207 Posts

Posted - 2010-03-25 : 06:21:11
Hi there,

I'd like to strip charactors to the left of a certain charactor. I can find out how to strip charactors to the right but this doesn't seem to apply in the same way.

I simply want to strip anything to the left of the charactor £

for example:
SMD0023774 Bankton 26100 12/03/2010 £99.30

I want to become:
99.30

Please can anyone help me here

Thanks:)

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-03-25 : 06:24:32
[code]
declare @str varchar(100)

select @str = 'SMD0023774 Bankton 26100 12/03/2010 £99.30'

select right(@str, charindex('£', reverse(@str)) - 1)
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

cidr
Posting Yak Master

207 Posts

Posted - 2010-03-25 : 06:54:49
Thank you khtan, life saver:)
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-03-25 : 09:02:12
or



declare @str varchar(100)

select @str = 'SMD0023774 Bankton 26100 12/03/2010 £99.30'

select substring(@str,charindex('£',@str)+1,len(@str))


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

cidr
Posting Yak Master

207 Posts

Posted - 2010-04-05 : 08:33:13
Thanks madhivanan, I'll keep both in mind

:)
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-04-05 : 09:55:32
Another variant:-

declare @str varchar(100)

select @str = 'SMD0023774 Bankton 26100 12/03/2010 £99.30'

select stuff(@str,1,charindex('£',@str),'')


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-04-05 : 10:09:16
Also refer
http://beyondrelational.com/blogs/madhivanan/archive/2009/11/18/parsing-a-string.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -