cchart3 (4/6/2009)
I built a simple procedure below to learn more tsql. The output of the print statement produces the correct output. I can take the output of the print statemenet and it executes in the same query window and it works properly. I even tried running this as a job that executes as "sa" and received the same error. This is written in SQL Server 2008.create proc [dbo].[sp_delete_old_files] @backupDir varchar(50),
@exttype varchar(3)
as
declare @olddate varchar(19)
declare @deletefiles varchar(100)
begin
set @olddate = CONVERT(VARCHAR, GetDate() - 1,126)
set @deletefiles = 'master.dbo.xp_delete_file 0,N''' + @backupDir +
''',N''' + @exttype + ''',N''' + @olddate + ''',1'
print @deletefiles
exec @deletefiles
end
run this command
exec sp_delete_old_files 'c:\testfolder', 'txt'
get this output and error
master.dbo.xp_delete_file 0,N'c:\testfolder',N'txt',N'2009-04-05T12:53:54',1
Msg 2812, Level 16, State 62, Procedure sp_delete_old_files, Line 14
Could not find stored procedure 'master.dbo.xp_delete_file 0,N'c:\testfolder',N'txt',N'2009-04-05T12:53:54',1'
Try this:
exec (@deletefiles)