当前位置: 代码迷 >> ASP.NET >> SQL获取当前时间并转换为数字有关问题
  详细解决方案

SQL获取当前时间并转换为数字有关问题

热度:5031   发布时间:2013-02-25 00:00:00.0
SQL获取当前时间并转换为数字问题
SQL获取当前时间并转换为数字,例如:今天第一次添加数据ID为:201205150001,第二次添加则为201205150002,第二天5月16号添加,则为201205160001。请问这个SQL代码要怎么写?谢谢

------解决方案--------------------------------------------------------
SQL code
declare @count intset @count = select count(1)+1 from table where ....select cast(year(getdate())as char(4))+       case when month(getdate())<10 then '0'+cast(month(getdate()) as char(1)) else cast(month(getdate()) as char(2)) end+       case when day(getdate())<10 then '0'+cast(day(getdate()) as char(1)) else cast(day(getdate()) as char(2)) end+       isnull(replicate('0',4-len(@count)),'')+cast(@count as char(4))
  相关解决方案