How can I a SQL Server Agent job if a file exists in a server folder?

夙愿已清 提交于 2019-12-02 15:35:45

问题


I need to import a flat file daily. The file changes its name every day. After the file is processed, it needs to be moved to another folder.

I noticed I can schedule jobs in the SQL Server Agent, and that I can tell it to run every hour or so and that I am able to add CMD commands to it.

The solution I found was to run a script to check if the file exists, since the folder should be empty or have at least one file.

If the file exists, the script renames the file to one used in the SSIS package and then it runs the SSIS package.

After the whole thing is done, it should rename the file again based on today's date and move it to another folder.

If the file does not exist, then it should do nothing and wait another hour or so to run again.

What's the best solution to this scenario? Is the script a good idea? Maybe is it possible to add the if/else -for the file exists- into the SSIS package? Or even make the script run from the SSIS package itself instead of adding it to the Server Agent?

EDIT:

It seems I was a little naïve, it's possible to run VB scripts from the server. Would that be the recommended solution? It does solve my problem, but I'm just wondering if it's a good idea.


回答1:


This solves all my questions:

http://www.sqlservercentral.com/articles/Integration+Services+%28SSIS%29/90571/



来源:https://stackoverflow.com/questions/27315732/how-can-i-a-sql-server-agent-job-if-a-file-exists-in-a-server-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!