SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


tsql can not find procedure xp_delete_file from procedure


tsql can not find procedure xp_delete_file from procedure

Author
Message
cchart3
cchart3
Old Hand
Old Hand (328 reputation)Old Hand (328 reputation)Old Hand (328 reputation)Old Hand (328 reputation)Old Hand (328 reputation)Old Hand (328 reputation)Old Hand (328 reputation)Old Hand (328 reputation)

Group: General Forum Members
Points: 328 Visits: 127
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'
Lynn Pettis
Lynn Pettis
SSC Guru
SSC Guru (90K reputation)SSC Guru (90K reputation)SSC Guru (90K reputation)SSC Guru (90K reputation)SSC Guru (90K reputation)SSC Guru (90K reputation)SSC Guru (90K reputation)SSC Guru (90K reputation)

Group: General Forum Members
Points: 90452 Visits: 38945
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)

Cool
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)
Jerry Hung
Jerry Hung
Hall of Fame
Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)

Group: General Forum Members
Points: 3306 Visits: 1208
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
cchart3
cchart3
Old Hand
Old Hand (328 reputation)Old Hand (328 reputation)Old Hand (328 reputation)Old Hand (328 reputation)Old Hand (328 reputation)Old Hand (328 reputation)Old Hand (328 reputation)Old Hand (328 reputation)

Group: General Forum Members
Points: 328 Visits: 127
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
Lynn Pettis
Lynn Pettis
SSC Guru
SSC Guru (90K reputation)SSC Guru (90K reputation)SSC Guru (90K reputation)SSC Guru (90K reputation)SSC Guru (90K reputation)SSC Guru (90K reputation)SSC Guru (90K reputation)SSC Guru (90K reputation)

Group: General Forum Members
Points: 90452 Visits: 38945
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?

Cool
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)
cchart3
cchart3
Old Hand
Old Hand (328 reputation)Old Hand (328 reputation)Old Hand (328 reputation)Old Hand (328 reputation)Old Hand (328 reputation)Old Hand (328 reputation)Old Hand (328 reputation)Old Hand (328 reputation)

Group: General Forum Members
Points: 328 Visits: 127
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.
Lynn Pettis
Lynn Pettis
SSC Guru
SSC Guru (90K reputation)SSC Guru (90K reputation)SSC Guru (90K reputation)SSC Guru (90K reputation)SSC Guru (90K reputation)SSC Guru (90K reputation)SSC Guru (90K reputation)SSC Guru (90K reputation)

Group: General Forum Members
Points: 90452 Visits: 38945
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.

Cool
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)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search