Gerando arquivo com BCP incluindo data no nome do arquivo.

Pessoal segue script de como gerar um arquivo formatado com BCP colocando o nome com data no arquivo.
Maiores informações:
https://docs.microsoft.com/pt-br/sql/tools/bcp-utility?view=sql-server-ver15
 
Guys follow script how to generate a file formatted with BCP putting the name with date in the file.
More information:
https://docs.microsoft.com/en-us/sql/tools/bcp-utility?view=sql-server-ver15
 
declare @sql varchar(8000)
select  @sql = 'bcp "select 1"  queryout "\\192.168.0.45\temp\ARQUIVOTESTE'+REPLACE(REPLACE(CONVERT(VARCHAR,GETDATE(),120),' ','_'),':','_')+'.csv" -c -t, -T -S '+ @@servername
exec xp_cmdshell @sql
SQL

Leave a Reply

Your email address will not be published. Required fields are marked *

search previous next tag category expand menu location phone mail time cart zoom edit close