设为首页 加入收藏

TOP

mssql对文件夹里面文件进行重命名,前面加上时间戳
2014-11-24 02:54:50 来源: 作者: 【 】 浏览:4
Tags:mssql 文件夹 里面 文件 进行 命名 前面 加上 时间
mssql对文件夹里面文件进行重命名,前面加上时间戳
[sql]
alter proc sp_filerename ( @dirpath varchar(1024))
as
declare @dirsql varchar(4000),@sql varchar(4000)
set @dirsql= ' dir ' + @dirpath +' /b/a'
create table #tmp ( dirfile varchar(1024),mark char(1) default 'N' )
insert #tmp
exec xp_cmdshell @dirsql
declare c cursor for
select 'exec xp_cmdshell '' rename ' + @dirsql
+ dirfile
+ convert(varchar(8),GETDATE(),112)
+ '_'
+ right('0'+cast(DATEPART(hour,getdate())as varchar),2)
+right('0'+cast(DATEPART(minute,getdate())as varchar),2)
+right('0'+cast(DATEPART(second,getdate())as varchar),2)
+'_'+ dirfile + ''''
from #tmp
where dirfile is not null
open c
fetch next from c into @sql
while @@FETCH_STATUS = 0
begin
exec(@sql);
fetch next from c into @sql
end
close c
deallocate c
drop table #tmp;
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇菜鸟SQL笔记0000_0000:Group By的.. 下一篇SQL puzzles and answers读书笔记..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·「链表」是一种怎样 (2025-12-25 19:20:51)
·C 语言中的链表有哪 (2025-12-25 19:20:48)
·c语言中的链表怎么学 (2025-12-25 19:20:45)
·Redis 分布式锁全解 (2025-12-25 17:19:51)
·SpringBoot 整合 Red (2025-12-25 17:19:48)