SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Error on Stored Procedure need help
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

zero1de
Yak Posting Veteran

Germany
98 Posts

Posted - 08/21/2014 :  04:25:33  Show Profile  Reply with Quote
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

Edited by - zero1de on 08/21/2014 09:34:02

gbritton
Flowing Fount of Yak Knowledge

1768 Posts

Posted - 08/21/2014 :  07:53:24  Show Profile  Reply with Quote
What error do you get?
Go to Top of Page

zero1de
Yak Posting Veteran

Germany
98 Posts

Posted - 08/21/2014 :  09:09:42  Show Profile  Reply with Quote
Sorry i found the syntax error now but i must check if the logic works :)

Edited by - zero1de on 08/21/2014 09:33:33
Go to Top of Page

zero1de
Yak Posting Veteran

Germany
98 Posts

Posted - 08/21/2014 :  10:15:39  Show Profile  Reply with Quote
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?


Edited by - zero1de on 08/21/2014 10:16:13
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000