Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

tsql can not find procedure xp_delete_file from procedure Expand / Collapse
Author
Message
Posted Monday, April 6, 2009 12:06 PM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Tuesday, December 2, 2014 10:24 AM
Points: 314, Visits: 126
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'
Post #691318
Posted Monday, April 6, 2009 1:24 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Yesterday @ 5:09 PM
Points: 20,896, Visits: 32,929
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)




Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Post #691392
Posted Tuesday, April 7, 2009 9:52 AM


Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Tuesday, December 2, 2014 8:26 AM
Points: 775, Visits: 1,203
A blog on xp_delete_file
http://sqlblog.com/blogs/andy_leonard/archive/2009/03/11/xp-delete-file.aspx

declare @DeleteDate nvarchar(50)
declare @DeleteDateTime datetime
set @DeleteDateTime = DateAdd(hh, -24, GetDate())
set @DeleteDate = (Select Replace(Convert(nvarchar, @DeleteDateTime, 111), '/', '-') + 'T' + Convert(nvarchar, @DeleteDateTime, 108))
EXECUTE master.dbo.xp_delete_file 0,N'E:\WSSLogs',N'log',@DeleteDate,1



SQLServerNewbie

MCITP: Database Administrator SQL Server 2005
Post #692222
Posted Tuesday, April 7, 2009 5:38 PM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Tuesday, December 2, 2014 10:24 AM
Points: 314, Visits: 126
Jerry,

I do not understand why I would want to do something in three lines that I can do in one. My time statement seems much more efficient. Also you can pass in variables to my sql. You can use it in all systems and you could use it for bak, log files, and etc. I am new to TSQl and are more familiar with oracle, but usually less code is better and variables are always better than hard coding. Is there something I am missing?


create procedure both_the_same
as
declare @DeleteDate nvarchar(50)
declare @olddate varchar(19)
declare @DeleteDateTime datetime
set @DeleteDateTime = DateAdd(hh, -24, GetDate())
set @DeleteDate = (Select Replace(Convert(nvarchar, @DeleteDateTime, 111), '/', '-') + 'T' + Convert(nvarchar, @DeleteDateTime, 108))

set @olddate = CONVERT(VARCHAR, GetDate() - 1,126)
print @DeleteDate
print @olddate


exec both_the_same
2009-04-06T18:28:17
2009-04-06T18:28:17
Post #692640
Posted Tuesday, April 7, 2009 7:50 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Yesterday @ 5:09 PM
Points: 20,896, Visits: 32,929
Curious, you respond to Jerry, but not a word about wether or not my suggested change helped you or not? Sorry, but something is missing there, don't you think?



Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Post #692691
Posted Tuesday, April 7, 2009 9:28 PM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Tuesday, December 2, 2014 10:24 AM
Points: 314, Visits: 126
Lynn,

Sorry I did not reply to reply to your response. Your answer worked great. I responded to the other answer, because it did not make since to me why you would do more work than you needed. I am new to TSQL but his code looked like it was less efficient than my code. I was hoping I was missing something from his what he posted and that I was looking at something wrong. I am always trying to learn. Again think for your answer, it was exactly what I needed.
Post #692719
Posted Tuesday, April 7, 2009 9:35 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Yesterday @ 5:09 PM
Points: 20,896, Visits: 32,929
Glad to hear it worked. Just so you know, it is just common curtesy to let people know if your problem has been solved and how. This is especially true if you find your own resolution. Others may have similar issues/problems and seeing your may help.


Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Post #692722
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse