ms sql 2015

I am bulk loading a file nightly and want to rename the file as part of the store procedure.
In stored procedure do bulk load and then rename the file name so that you can tell the file has been bulk loaded.
Bryon HuffmanAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ITSysTechSenior Systems AdministratorCommented:
Are you using MSSQL 2016 the heading says 2015?  thanks
Bryon HuffmanAuthor Commented:
Sorry ms sql 2008
Pawan KumarDatabase ExpertCommented:
Please find the complete solution below -

	Name VARCHAR(40)

INSERT BulkExamples
FROM 'c:\pawan\tblName_March_2015.txt'

SELECT * FROM BulkExamples

Open in new window


SELECT * FROM BulkExamples
ID          Name
----------- ----------------------------------------
1           Pawan
2           Sharlee
3           Jason
1           Pawan
2           Sharlee
3           Jason

(6 row(s) affected)

Open in new window

For rename the file you can download the code from

Execution -
exec sp_ReplaceFileOrDirNames @pathToObject= 'c:\pawan',

Open in new window

For renaming if the above solution does not work we can also use xp_cmdshell.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Vitor MontalvãoMSSQL Senior EngineerCommented:
You shouldn't use SQL Server to perform operation system tasks as renaming a file.
I will recommend you a solution that runs from the Windows command prompt. You can use the Windows Task Scheduler to schedule the following script to run it daily:
bcp databaseName.dbo.FileName IN C:\importFiles\FileName.bcp -c -T
ren C:\importFiles\FileName.bcp C:\importFiles\NewFileName.bcp

Open in new window

BCP is a utility that performs the Bulk Insert and ren is the rename command.
Vitor MontalvãoMSSQL Senior EngineerCommented:
Bryon, is your issue solved?
Pawan KumarDatabase ExpertCommented:
Hi Bryon,
Did my comment worked for you ?

Vitor MontalvãoMSSQL Senior EngineerCommented:
2 different solutions provided.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.