terça-feira, 21 de abril de 2009



Sp para copiar ficheiros muito útil

USE [aspnetdb] -- Replace with your DB
GO
/****** Object:  StoredProcedure [dbo].[usp_copiamsg]    Script Date: 04/21/2009 09:22:20 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
Create procedure [dbo].[usp_copiamsg]
@msg as varchar(200),
@input as varchar(100)
,@retorno as varchar(200) output
as
Begin 

declare @drive as varchar(100)
declare @drive_dest as varchar(100)
declare @path as varchar(800)
declare @path_dest as varchar(800)
declare @cmd as varchar(800)
declare @ext as char(3)

set @path_dest='\Dest_Path\'
-- Para Exemplo, não esquecer barra de directorio final 
--
set @path='\PROGRA~1\DATA\'
set @drive='c:'
set @drive_dest='d:'
set @cmd='copy '+@drive+@path+@msg+@ext
set @cmd=@cmd+@drive_dest+@path_dest+ltrim(rtrim(@input))+(select  cast(day(getdate())  as varchar(2)))
+(select  cast(month(getdate())  as varchar(2)))
+(select  cast(year(getdate())  as varchar(4)))
+replace((select convert(varchar(8),getdate(),108)),':','')+@ext




-- Para Testar Caminhos e Visualizar
-- select @cmd

exec master..xp_cmdshell @cmd ,no_output

Set @retorno=@drive_dest+@path_dest+ltrim(rtrim(@input))+(select  cast(day(getdate())  as varchar(2)))
+(select  cast(month(getdate())  as varchar(2)))
+(select  cast(year(getdate())  as varchar(4)))
+replace((select convert(varchar(8),getdate(),108)),':','')+@ext

end


Sem comentários:

Enviar um comentário