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