SQL。搬运转载

SQL日期

SELECT GETDATE() as '当前日期',
DateName(year,GetDate()) as '年',
DateName(month,GetDate()) as '月',
DateName(day,GetDate()) as '日',
DateName(dw,GetDate()) as '星期',
DateName(week,GetDate()) as '周数',
DateName(hour,GetDate()) as '时',
DateName(minute,GetDate()) as '分',
DateName(second,GetDate()) as '秒'

sql左侧补0

--第一种方法(五个0,代表五位数)
SELECT RIGHT('00000'+CAST(ID AS nvarchar(50)),5) FROM dbo.TableName --左边补0,如 00001,00039
SELECT LEFT(CAST(ID AS nvarchar(50))+'00000',5) FROM dbo.TableName --右边补0,如 10000,39000
--第二种方法 SELECT REPLICATE('0',5-len('39'))+'39' --左边补0, 如 00039 SELECT '39' + REPLICATE('0',5-len('39')) --右边补0,如 39000

 

posted @ 2020-02-25 13:00  ZhiPeng007  阅读(139)  评论(0编辑  收藏  举报