[英]Extract Date from varchar field in SQL Server 2008
I have a table which has only 1 large column named Details
; 我有一个表,只有一个大列,名为
Details
; each record looks similar to this: 每条记录看起来都与此类似:
Record#1: ...ID: <klsdhf89435> Date: 1 Jun 2011 12:28:14 From: "Yahoo"...
Record#2: ...Subject: test Date: Fri, 24 May 2010 13:18:43 -0500 ID: <7532432423>...
Record#3: ...ID: <234321fd> Date: 14 Jun 2010 12:28:14 From: "Gmail"...
Record#4: ...ID: <12434> Date: 1 Jun 2011 12:28:14 From: "Yahoo"...
I would like the subtract the Date only. 我只想减去日期。 So, for those 4 records, I would like to extract:
因此,对于这4条记录,我想提取:
1 Jun 2011 12:28:14
Fri, 24 May 2010 13:18:43 -0500
14 Jun 2010 12:28:14
1 Jun 2011 12:28:14
Please note that the double space from before "From" or before "ID" is a new line character which is Char(10)
in SQL Server. 请注意,“ From”之前或“ ID”之前的双精度空格是换行符,在SQL Server中为
Char(10)
。
Thanks in advance 提前致谢
SELECT SUBSTR(Details, LOCATE('Date: ', Details), LOCATE(' From:', Details) - LOCATE('Date: ', Details))
FROM TABLENAME
Consider parsing the date into a new date column when the row is inserted. 考虑在插入行时将日期解析为新的日期列。
http://dev.mysql.com/doc/refman/5.0/en/string-functions.html http://dev.mysql.com/doc/refman/5.0/en/string-functions.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.