Results 1 to 6 of 6

Thread: File Event

  1. #1
    Join Date
    Oct 2002
    Location
    queens
    Posts
    139

    File Event

    Hi,

    Can anyone help me with this?

    I need to run an SQL job if a specific file exists. Actually, that specific files gets created different time in different day. I need to run the job when the file arrives. Is there any way to do this in SQL? I have done this in seagate scheduler but I need to do it in SQL.
    Please help!!!!!!!

    Thanks.

  2. #2
    Join Date
    Sep 2002
    Location
    Fantasy
    Posts
    4,254
    create your job which needs to run if the file exist. (say Job1)

    create a job which runs every 5 minutes or one minute say (job2)
    In this jobstep write the following code

    DECLARE @result int
    EXEC @result = xp_cmdshell 'dir c:\testwww.txt', no_output
    IF (@result = 0)
    begin
    EXEC sp_start_job @job_name = 'Job1'
    xp_cmdshell 'ren c:\testwww.txt c:\testwww_Old.txt', no_output
    end

  3. #3
    Join Date
    Sep 2002
    Location
    Fantasy
    Posts
    4,254
    if you dont like the above method you can also use the undocumented procedure xp_fileexist

  4. #4
    Join Date
    Oct 2002
    Location
    queens
    Posts
    139
    Thanks very much, I'll try both and let you know which works better.

  5. #5
    Join Date
    Oct 2002
    Location
    queens
    Posts
    139
    Thanks very much, I'll try both and let you know which works better.

  6. #6
    Join Date
    Oct 2002
    Location
    queens
    Posts
    139
    Thanks Mak, the first approach worked perfectly except for renaming the file. It says that the syntax is not correct, I got arround with that by using move command.

    Thanks again.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •