Author |
Topic  |
|
bhushan_juare
Starting Member
45 Posts |
Posted - 02/13/2013 : 03:49:17
|
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
|
Whats A and B? cant make out from query as it specifies only single column
------------------------------------------------------------------------------------------------------ SQL Server MVP http://visakhm.blogspot.com/
|
 |
|
djj55
Constraint Violating Yak Guru
USA
352 Posts |
Posted - 02/13/2013 : 12:01:42
|
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 |
 |
|
jimf
Flowing Fount of Yak Knowledge
USA
2875 Posts |
Posted - 02/13/2013 : 15:13:16
|
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 |
 |
|
|
Topic  |
|