设为首页 加入收藏

TOP

mssql对文件夹里面文件进行重命名,前面加上时间戳
2014-11-24 02:54:50 来源: 作者: 【 】 浏览:3
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-24 12:48:26)
·c++是否应避免使用普 (2025-12-24 12:48:23)
·如何通俗易懂学会 C+ (2025-12-24 12:48:21)
·在 C 语言函数中,如 (2025-12-24 12:19:41)
·C盘里面的AppData文 (2025-12-24 12:19:38)