修剪SQL中的列值 [英] Trim a column value in SQL

查看:65
本文介绍了修剪SQL中的列值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类型为varchar的数据库字段END_TIME。

其中包含以下模式的数据:



END_TIME

---------

09/06/2013 05:07:02 PM





现在我只需要05:07:02 PM部分。我怎么能实现它呢?





我还有

TOTAL_TIME

--------------

00小时01分40秒





我只需要显示几分钟。像1.4分钟或1分40秒。



请帮助

I have a database field END_TIME of type varchar.
The data in it of following pattern:

END_TIME
---------
09/06/2013 05:07:02 PM


Now I only need "05:07:02 PM" part. How can I achieve it?


Also I have
TOTAL_TIME
--------------
00 hrs 01 mins 40 secs


I need to show only minutes. Like 1.4 mins or 1 min 40sec.

Please help

推荐答案





你可以使用Substring来提取这样的字符串部分,如果你的列名是salesdate并且它包含你给出的日期,那么这个列的数据类型是varchar。然后你就可以去了。





从测试中选择SUBSTRING(salesdate,11,14)


在子字符串函数中,salesdate是columnname,11是提取的起始点,14是你需要提取字符串的长度。



这样你就可以进行提取然后连接以加入两个值。这会有所帮助。





问候,

Mubin
Hi ,

You can use Substring for extraction of part of string like this, if your column name is salesdate and it contains date given by you , data type of this column is varchar. then you can go for this.


select SUBSTRING(salesdate,11,14 ) from test

In substring function salesdate is columnname,11 is starting point of extraction,14 is length upto which you need to extract the string.

This way you can do extraction and then concatination to join two values.hope this will helps.


Regards,
Mubin


您好,



您也可以尝试以下代码...

Hi,

You can try below code also...
DECLARE @END_TIME VARCHAR(50)
SET @END_TIME = '09/06/2013 05:07:02 PM'
SELECT SUBSTRING(@END_TIME, CHARINDEX(' ',@END_TIME ,1)+1,20)



让我知道你想用什么逻辑来00小时01分40秒到1.4分钟或1分40秒



此致,

GVPrabu


Let me know what logic you want to use to frame "00 hrs 01 mins 40 secs" to "1.4 mins or 1 min 40sec"

Regards,
GVPrabu


这篇关于修剪SQL中的列值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆