如何在同一个select sql查询中使用多个子字符串 [英] how to use multiple substring in same select sql query
本文介绍了如何在同一个select sql查询中使用多个子字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
hi
我想在单列的select查询中使用多个子字符串。
所以对于exp。我有价值221415525
i想要它
22:14:155
hi
i want to use multiple substring in select query for single column.
so for exp. i have value as 221415525
i want to make it
22:14:155
can i use substring in select as
SELECT ' ' + substring('221415525', 1, 2)
+ ':' + substring('143825', 3, 2)
+ ':' + substring('143825', 5, 2), name from mytable
推荐答案
DECLARE @STR AS NVARCHAR(MAX) = '221415525'
SELECT CONVERT(DATETIME, SUBSTRING(@STR, 1, 2) + ':' + SUBSTRING(@STR, 3, 2) + ':' + SUBSTRING(@STR, 5, 2) + ':' + SUBSTRING(@STR, 7, 2), 114)
我找到答案
ie。
CONVERT(TIME(0),CONVERT(datetime,1.09796836411745)),
这给出了输出如02:21:04
I found answer
ie.
CONVERT(TIME(0),CONVERT(datetime,1.09796836411745)),
this gives output as 02:21:04
这篇关于如何在同一个select sql查询中使用多个子字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文