Need to create step in SQL job which check if file exist because if file exists it needed to be stop but if file not exist to continue with next step.
xp_fileexist
not allowed in sql query.
-
if you use SQLServer Agent, can't you make an Operating System or Powershell command ?– irimiasNov 30, 2016 at 10:30
-
yes, but on one way or another SQL agent will finish with success, I want to stop if file exists.– Darko MilicNov 30, 2016 at 10:37
1 Answer
You can use a Powershell command on your job and raise an error if your file is not found so that your job will stop. Something like:
if (-not (Test-Path $file))
{
throw [System.IO.FileNotFoundException] "$file not found."
}