text file with date

  • i have a text file "xxx_xxxx.xxx.xxxxx_xxxxxxxx_xxxx_09_28_10.txt" and text file is generated daily with date in above format .

    I have a condition

    DECLARE @file_exists int

    SET @file_exists=0

    exec xp_fileexist 'xxx_xxxx.xxx.xxxxx_xxxxxxxx_xxxx_09_28_10.txt', @file_exists OUTPUT

    If @File_Exists =1

    Do some thing xxxx

    else

    Do something yyyyy

    is there any way to auotomate the condition to run daily with current date ? thanks in advance 🙂

  • See if the following helps you: http://www.nigelrivett.net/SQLTsql/CheckIfFileExists.html

  • In addition, I think the following code snippet will also help:

    declare @FileName varchar(128);

    select

    @FileName = 'xxx_xxxx.xxx.xxxxx_xxxxxxxx_xxxx' +

    '_' + SUBSTRING(CONVERT(varchar(10), getdate(), 10),1,2) +

    '_' + SUBSTRING(CONVERT(varchar(10), getdate(), 10),4,2) +

    '_' + SUBSTRING(CONVERT(varchar(10), getdate(), 10),7,2) +

    '.txt'

    ;

    select @FileName;

  • DECLARE @file_exists int

    DECLARE @MYFILE VARCHAR(300)

    set@MYFILE='xxx_xxxx.xxx.xxxxx_xxxxxx_xxxxx_'+Replace(CONVERT(VARCHAR(8),GETDATE(),1),'/','_')+'.txt'

    select @MYFILE

    SET @file_exists=0

    exec xp_fileexist @MYFILE, @file_exists OUTPUT

    If @File_exists=1

    do something xxxx

    else

    do something yyyy

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply