Hi I have this value in a column
11-1-11111-349b65eda2-4f8e-413d-b76a-6a2c13d6e494OctWed0800422015-request-response.xml
How would I parse this using SQL to get only:
11-1-11111-349b65eda2-4f8e-413d-b76a-6a2c13d6e494OctWed0800422015
In SQL-Server you could use this approach if the right side is always -request-response.xml:
SELECT FileName,
Leftpart = LEFT(FileName,CHARINDEX('-request-response.xml',FileName)-1)
FROM MyTable
This is more fail-safe:
WITH CTE AS
(
SELECT FileName,
Length = CHARINDEX('-request-response.xml',FileName) -1
FROM MyTable
)
SELECT LeftPart = CASE WHEN Length < 0 THEN NULL
ELSE LEFT(FileName, Length) END
FROM CTE
left() and charindex(), which pretty much means SQL Server or Sybase.LEFT. That's why i've added the second approach.
-? Or maybe remove after length string> 65