Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

How t Split last two char from varchar dataset..? Expand / Collapse
Author
Message
Posted Wednesday, February 13, 2013 1:42 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Tuesday, May 14, 2013 12:14 AM
Points: 62, Visits: 358
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
Post #1419339
Posted Wednesday, February 13, 2013 2:52 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Thursday, May 16, 2013 9:16 AM
Points: 2,236, Visits: 6,486
What does the original data look like? What is the DDL for the table?


Not a DBA, just trying to learn

For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/

For better, quicker answers on SQL Server performance related questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/



If you litter your database queries with nolock query hints, are you aware of the side effects?
Try reading a few of these links...

(*) Missing rows with nolock
(*) Allocation order scans with nolock
(*) Consistency issues with nolock
(*) Transient Corruption Errors in SQL Server error log caused by nolock
(*) Dirty reads, read errors, reading rows twice and missing rows with nolock


LinkedIn | Blog coming soon (for sufficiently large values of "soon" )!
Post #1419361
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse