mitmit wrote
Anyone that can help me how exact to change the store procedure
Here's the original stored procedure out of 3.3.5.
Then SELECT SCOPE_IDENTITY() statement is moved up into the IF @FileID IS NULL block as shown in red.
Hopes this helps with your problem.
CREATE PROCEDURE dbo.AddFile
@PortalId int,
@FileName nvarchar(100),
@Extension nvarchar(100),
@Size int,
@WIdth int,
@Height int,
@ContentType nvarchar(200),
@Folder nvarchar(200),
@FolderID int
AS
DECLARE @FileID int
SET @FileID = (SELECT FileId FROM Files WHERE FolderID = @FolderID and FileName = @FileName)
IF @FileID IS NULL
BEGIN
INSERT INTO Files (
PortalId,
FileName,
Extension,
Size,
Width,
Height,
ContentType,
Folder,
FolderID
)
VALUES (
@PortalId,
@FileName,
@Extension,
@Size,
@Width,
@Height,
@ContentType,
@Folder,
@FolderID
)
SELECT SCOPE_IDENTITY()
END
ELSE
BEGIN
UPDATE Files
SET FileName = @FileName,
Extension = @Extension,
Size = @Size,
Width = @Width,
Height = @Height,
ContentType = @ContentType,
Folder = @Folder,
FolderID = @FolderID
WHERE FileId = @FileID
END
UPDATE Folders
SET LastUpdated = getUtcDate()
WHERE FolderID = @FolderID
--SELECT SCOPE_IDENTITY()
GO