SQLServer right函数 从右侧截取指定位数的字符串


right(字段名,n)

sql从右侧截取字符串。n代表从右侧截取的位数。

 

SELECT RIGHT('123456', 4)
SELECT LEFT('123456', 4)

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

举个栗子:

declare @starttime as datetime
declare @endtime as datetime
set @starttime = GETDATE()--'2018-06-19 17:08:02.000' 
set @endtime = '2018-06-20 17:08:02.000'

select right('00'+ cast(cast(datediff(ss ,@starttime,@endtime) / 3600 as int) as varchar),2) + ':' + 
right('00'+ cast(cast(datediff(ss ,@starttime,@endtime) % 3600 / 60 as int) as varchar),2) + ':' + 
right('00'+ cast(cast(datediff(ss ,@starttime,@endtime) % 60 as int) as varchar),2)

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM