0

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 ? – irimias Nov 30 '16 at 10:30
  • yes, but on one way or another SQL agent will finish with success, I want to stop if file exists. – Darko Milic Nov 30 '16 at 10:37
1

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."
}
  • different logic. If file exists then stop – Darko Milic Nov 30 '16 at 11:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.