首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

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

2012-09-08 
SQL获取当前时间并转换为数字问题SQL获取当前时间并转换为数字,例如:今天第一次添加数据ID为:201205150001

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)) 

热点排行