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.
Author |
Topic |
bhushan_juare
Starting Member
45 Posts |
Posted - 2013-02-13 : 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_DESCRIPTIONELSE SUBSTRING(GT.FG_DESCRIPTION, 1, CHARINDEX(' ', GT.FG_DESCRIPTION, 1) - 2) END) AS PROD_TYPEOutput comingA B14.00-24 32 PR BKT EM937 TL 14.00-2700/40-22.5 16 PR BKT FLOT648 TL 700/40-22.30.5L-32 12 PR BKT TR137 TR 30.5L-3Required OutputA B14.00-24 32 PR BKT EM937 TL TL700/40-22.5 16 PR BKT FLOT648 TL TL30.5L-32 12 PR BKT TR137 TR TRThanksBhushan |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-02-13 : 04:56:02
|
Whats A and B? cant make out from query as it specifies only single column------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
djj55
Constraint Violating Yak Guru
352 Posts |
Posted - 2013-02-13 : 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
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2013-02-13 : 15:13:16
|
I think he wants the last 2 alphas when there are 2 alphas in a rowdeclare @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)JimEveryday I learn something that somebody else already knew |
|
|
|
|
|