Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Error on Stored Procedure need help

Author  Topic 

zero1de
Posting Yak Master

105 Posts

Posted - 2014-08-21 : 04:25:33
I get the Procedure not to run, can somebody help me to get run the SP ?


USE [DWData];
GO
SET ANSI_NULLS ON;
GO
SET QUOTED_IDENTIFIER ON;

ALTER PROCEDURE usp_Qualco_Delete_Attachments(@SourceDir varchar(1024), @SourceFile varchar(512))
AS
DECLARE @SourceDirFOR varchar(255)
,@FileName varchar(512)
,@DynDelete varchar(512)
,@Error int

SET @SourceDirFOR = 'FOR %I IN ("' + @SourceDir + @SourceFile + '") DO @ECHO %~nxtI'
SET @Error = 0

-- Start temp table population(s).
CREATE TABLE #_File_Details_01
(Ident int IDENTITY(1,1)
,Output varchar(512))

INSERT INTO #_File_Details_01
EXEC master..xp_cmdshell @SourceDirFOR

CREATE TABLE #_File_Details_02
(Ident int
,[TimeStamp] datetime
,[FileName] varchar(255))

INSERT INTO #_File_Details_02
SELECT Ident, CONVERT(char(10), SUBSTRING([Output],1,10), 121) AS [TimeStamp]
,SUBSTRING([Output],21,255) AS [FileName] FROM #_File_Details_01 WHERE [Output] IS NOT NULL ORDER BY Ident
-- Start delete ops cursor.
DECLARE curDelFile CURSOR
READ_ONLY
FOR
-- I try to check if the File exsist in Table France on Field Abgleich, in this Field is the Filename saved.
SELECT [FileName]
FROM #_File_Details_02
where [Filename] in (Select abgleich FROM France)
OPEN curDelFile
FETCH NEXT FROM curDelFile INTO @FileName
WHILE (@@fetch_status <> -1)
BEGIN
IF (@@fetch_status <> -2)
BEGIN
SET @DynDelete = 'DEL /Q "' + @SourceDir + @FileName + '"'
EXEC master..xp_cmdshell @DynDelete
END
FETCH NEXT FROM curDelFile INTO @FileName
END
CLOSE curDelFile
DEALLOCATE curDelFile

DROP TABLE #_File_Details_01
DROP TABLE #_File_Details_02

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2014-08-21 : 07:53:24
What error do you get?
Go to Top of Page

zero1de
Posting Yak Master

105 Posts

Posted - 2014-08-21 : 09:09:42
Sorry i found the syntax error now but i must check if the logic works :)
Go to Top of Page

zero1de
Posting Yak Master

105 Posts

Posted - 2014-08-21 : 10:15:39
The SP is now cleanly compilied. But when i execute sp nothing is deleted? What it the problem?

File name = integration Lettre 2 purchase24147_241472012112809504511424147.doc
DB field Entry = integration Lettre 2 purchase24147_241472012112809504511424147.doc

quote:
Originally posted by gbritton

What error do you get?

Go to Top of Page
   

- Advertisement -