set   @data_2ago='Y:\'+'BACKUP_'+convert(varchar(10),getdate()-5,112)+'.bak'    if file(@data_2ago)
   set   @cmd   =   'del   '+   @data_5ago    
   exec   master..xp_cmdshell   @cmd   
end if以上 if file(@data_2ago) 语句不行,请教高手如何做呢? 请指教,谢谢!

解决方案 »

  1.   

    if file(@data_2ago)
    SQL 不認吧
      

  2.   

    exec master..xp_fileexist @filename,@result OUT
      

  3.   

    @result 就什么? 要如何定义?
      

  4.   

    SQL 判断一个文件是否存在!
    2009-09-08 13:24DECLARE 
    @retval   int, 
    @param1   int 
    EXECUTE   @retval=master..xp_fileexist   'd:\1.csv ',   @param1   OUTPUT   
    IF   @param1   =   0 
    PRINT   'File   does   not   exist! ' 
    ELSE 
    PRINT   'File   exists! 'create    proc p_QueryCheckFile
        @path nvarchar(1000),
        @fname nvarchar(250)
    as--检查文件是否已经存在
    if right(@path,1)<>'\' 
        set @path=@path+'\'
    if exists (select * 
                from sysobjects 
                    where type='u'
                        and 
                     name = 'temp_xp_fileexist')
        begin
            drop table temp_xp_fileexist
        end
            
    create table temp_xp_fileexist(a bit,b bit,c bit)
    declare @sql nvarchar(1000)
    set @sql=@path+@fname
    insert into temp_xp_fileexist 
        exec master..xp_fileexist @sql
     
    我找到了方法, 谢谢不知名的网友代码