简体   繁体   English

解析SQL查询

[英]Parse on SQL query

from an old datatable (.dbf file) in a non formated column I got the a time value with 2 extra alphabetic letters. 从一个未格式化的列中的旧数据表(.dbf文件)中,我获得了带有两个额外字母的时间值。 ejpl: 12:34:56AB = HH:mm:ssAB. ejpl: 12:34:56AB = HH:mm:ssAB。 The 2 letters stand for some userindefication(users inicials). 2个字母代表某些用户定义(用户首字母缩写)。 How can I separate the time with this extra 2 letters in 2 different colums? 如何在两个不同的列中用这两个额外的字母分隔时间?

In SQL Server you can use right() and left() : 在SQL Server中,可以使用right()left()

select right(timeval, 2) as initials,
       left(timeval, 8) as time

In fact, these functions are available in most databases. 实际上,这些功能在大多数数据库中都可用。 And, all databases have similar functionality even if the functions are slightly different. 并且,即使功能略有不同,所有数据库也具有相似的功能。

Pure Standard SQL: 纯标准SQL:

select substring(col from 1 for 8) as timepart,
       substring(col from 9) as initials

In case there are no initials this will return an empty string, Gordon's will return the seconds instead. 如果没有首字母,将返回一个空字符串,而戈登将返回秒。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM