嗨,我在列
中有这个值11-1-11111-349b65eda2-4f8e-413d-b76a-6a2c13d6e494OctWed0800422015-request-response.xml
我将如何使用SQL解析此内容:
11-1-11111-349b65eda2-4f8e-413d-b76a-6a2c13d6e494OctWed0800422015
答案 0 :(得分:1)
在SQL-Server中,如果右侧始终为-request-response.xml
:
SELECT FileName,
Leftpart = LEFT(FileName,CHARINDEX('-request-response.xml',FileName)-1)
FROM MyTable
这更加安全无虞:
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