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
 General SQL Server Forums
 New to SQL Server Programming
 delete right and left part and show middle string

Author  Topic 

rash901
Starting Member

8 Posts

Posted - 2014-10-31 : 02:09:46
i have a column name remarks and i want to retrieve data like by deleting some of the leading charaters and some last characters and show the middle one.

like remarks has CALLTRANSFER_OVER_SIP:XfrTime=86.05599975585938_en
and i want to show only "XfrTime=86.05599975585938" this much

ahmeds08
Aged Yak Warrior

737 Posts

Posted - 2014-10-31 : 02:56:01
is the format of data always the same?

Javeed Ahmed
https://www.linkedin.com/pub/javeed-ahmed/25/5b/95
Go to Top of Page

rash901
Starting Member

8 Posts

Posted - 2014-10-31 : 05:28:23
yes the format is the same though the value of XfrTime differs..
Go to Top of Page

Ifor
Aged Yak Warrior

700 Posts

Posted - 2014-10-31 : 12:23:38
[code]
-- *** Test Data ***
CREATE TABLE #t
(
remarks varchar(8000) NOT NULL
);
INSERT INTO #t
SELECT 'CALLTRANSFER_OVER_SIP:XfrTime=86.05599975585938_en';
-- *** End Test Data ***

WITH StartPos
AS
(
SELECT remarks
, CHARINDEX('XfrTime=', remarks) AS XfrTimePos
FROM #t
)
SELECT SUBSTRING(remarks, XfrTimePos + 8, CHARINDEX('_', remarks, XfrTimePos) - XfrTimePos - 8) AS XfrTime
FROM StartPos;
[/code]
Go to Top of Page
   

- Advertisement -