我想连接两个TIME
列并显示为一列。
示例:
结果应该是:
9:00-12:00
答案 0 :(得分:1)
通用SQL:
-- hh:mm:ss
SELECT 'result:' + CONVERT(CHAR(6), FromTime, 8) + '-' + CONVERT(CHAR(6), ToTime)
FROM yourTable
MySQL的:
-- hh:mm
SELECT 'result:' + DATE_FORMAT(FromTime, '%H:%i') + '-' + DATE_FORMAT(ToTime, '%H:%i')
FROM yourTable
SQL Server:
-- hh:mm
SELECT 'result:' + convert(char(2), DATEPART(hh, FromTime)) + ':' +
CONVERT(CHAR(2), DATEPART(mm, FromTime)) + '-' +
CONVERT(CHAR(2), DATEPART(hh, ToTime)) + ':' +
CONVERT(CHAR(2), DATEPART(mm, ToTime))
FROM yourTable
答案 1 :(得分:1)
declare @FromTime time
declare @ToTime time
set @FromTime='9:00'
set @ToTime='12:00'
select cast(@FromTime as varchar(10))+ '-' + cast(@ToTime as varchar(10)) as result
答案 2 :(得分:0)
您可以使用convert
select convert(VARCHAR(5),getdate(),108) + ' - ' + convert(VARCHAR(5),getdate()-1,108)