When I add a file to a database I have to retreive the max sort order number add one to it and then use that value to populate the sort order field.
I am getting an error message at my ELSE when I create this stored proc:
CREATE PROCEDURE [dbo].oc_OnlineCaseFileAdd
@CaseId int,
@FileId int,
@FileName nvarchar(100),
@FileDescription nvarchar(400)
AS
declare @ResultCount int
Select @ResultCount = Count(*) From oc_OnlineCaseFile
Where FileId = @FileId
IF @ResultCount = 0 /* if the file does not exist INSERT */
/* Retreive the highest sortorder */
Declare @HighestSortOrder int
Select @HighestSortOrder = Max(SortOrder) + 1
From oc_onlinecasefile
Where CaseId = @CaseId
INSERT INTO [dbo].oc_OnlineCaseFile /* Do I Insert the File Id here, it was not before) */
(
[CaseId],
[FileId],
[FileName],
[FileDescription],
[SortOrder]
)
VALUES
(
@CaseId,
@FileId,
@FileName,
@FileDescription,
@HighestSortOrder
)
ELSE /* if the file does exist UPDATE the File Info */ <<<<<<<<<<<<THIS IS WHERE IT IS GVING ME PROBLEMS, AT LEAST IN SQL ANAYZER <<<<<<<<<<<<<<<<<
EXEC [dbo].oc_OnlineCaseFileUpdate @FileId=@FileId, @FileDescription=@FileDescription
SELECT SCOPE_IDENTITY() AS NewIdentity, @ResultCount AS ResultCount
/* otherwise you run into a keyword issue with "Identity" */
GO