What I am trying to do is the following: Everyday I get a CSV file that eventually needs to be imported into SQL via Bulk Insert. This all has worked great for a long time but recently, one of the columns in the CSV file contains text that needs to be replaced before the bulk insert.
After some searching i found the following code for a BAT-file:
@echo off &setlocal
set "search=%1"
set "replace=%2"
set "textfile=Input.txt"
set "newfile=Output.txt"
(for /f "delims=" %%i in (%textfile%) do (
set "line=%%i"
setlocal enabledelayedexpansion
set "line=!line:%search%=%replace%!"
echo(!line!
endlocal
))>"%newfile%"
del %textfile%
rename %newfile% %textfile%
Now when i put this bat-file in the directory and double click to run it that works great. But the problem now is that i want to integrate it in a SQL Stored Procedure I put it in the procedure like this:
EXEC master..xp_CMDShell 'E:\FolderName\REPLACE.BAT'
When i try to run that i get the message "File not found" in SQL. Both for the stored procedure as for running it just as a query (under my own credentials, which are admin rights). Just to be sure i gave the SQL-user also full rights on the specific folder, but that didnt help either.
How can I get this work inside SQL Server?