Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 How to Split last two char from varchar dataset..?
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

bhushan_juare
Starting Member

45 Posts

Posted - 02/13/2013 :  03:49:17  Show Profile  Reply with Quote
Hi All,
This is the query i have written but unable to extract last two char..

max(CASE CHARINDEX(' ', GT.FG_DESCRIPTION, 1) WHEN 0 THEN GT.FG_DESCRIPTION
ELSE SUBSTRING(GT.FG_DESCRIPTION, 1, CHARINDEX(' ', GT.FG_DESCRIPTION, 1) - 2) END) AS PROD_TYPE

Output coming
A B
14.00-24 32 PR BKT EM937 TL 14.00-2
700/40-22.5 16 PR BKT FLOT648 TL 700/40-22.
30.5L-32 12 PR BKT TR137 TR 30.5L-3

Required Output
A B
14.00-24 32 PR BKT EM937 TL TL
700/40-22.5 16 PR BKT FLOT648 TL TL
30.5L-32 12 PR BKT TR137 TR TR

Thanks
Bhushan

Edited by - bhushan_juare on 02/13/2013 04:01:17

visakh16
Very Important crosS Applying yaK Herder

India
52326 Posts

Posted - 02/13/2013 :  04:56:02  Show Profile  Reply with Quote
Whats A and B? cant make out from query as it specifies only single column

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

Go to Top of Page

djj55
Constraint Violating Yak Guru

USA
352 Posts

Posted - 02/13/2013 :  12:01:42  Show Profile  Reply with Quote
If you know it is the last two characters then what about the RIGHT function? Since you used the CHARINDEX function I think you might look at the REVERSE function.

djj
Go to Top of Page

jimf
Flowing Fount of Yak Knowledge

USA
2875 Posts

Posted - 02/13/2013 :  15:13:16  Show Profile  Reply with Quote
I think he wants the last 2 alphas when there are 2 alphas in a row

declare @str varchar(50)='30.5L-32 12 PR BKT TR137 TR 30.5L-3'

select
SUBSTRING(@str,LEN(@str)-patindex('%[A-Z][A-Z]%',REVERSE(@str)),2)

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000