Question : Rowcount problem

I need to check if a file exists inside a stored proc. If it does exist  I call an update stored proc if it does not exist I run the insert statement.
I was trying to get a row count but had problems here is my stored proc:


CREATE PROCEDURE [dbo].oc_OnlineCaseFileAdd
                @FileId int,
      @CaseId int,
      @FileName nvarchar(100),
      @FileDescription nvarchar(400),
      @SortOrder int
AS

declare @ResultCount int
Set RowCount @ResultCount
Select FileId, @ResultCount ResultCount
From oc_OnlineCaseFile
Where FileId = @FileId

if (ResultCount = null || 0 )

//INSERT CODE

Else (ResultCout = 1)

//UPDATE CODE

 This is what I am doing to check for the rowcount:
---------------------------------
declare @ResultCount int
Set RowCount @ResultCount
Select FileId
From oc_OnlineCaseFile
Where FileId = 1
--------------------------
 I get the error message:

---------------------------

Server: Msg 507, Level 16, State 2, Line 2
Invalid argument for SET ROWCOUNT. Must be a non-null non-negative integer.

(1 row(s) affected)


Answer : Rowcount problem

that's because you have CREATE PROCEDURE at the top of your batch so it's creating a procedure.  If you want to test the logic first then you need to remove the CREATE PROCEDURE call and declare and set the parameters.  

/*
CREATE PROCEDURE [dbo].oc_OnlineCaseFileAdd
     @FileId int,
     @CaseId int,
     @FileName nvarchar(100),
     @FileDescription nvarchar(400),
     @SortOrder int
AS
*/

DECLARE @FileID int,
     @CaseId int,
     @FileName nvarchar(100),
     @FileDescription nvarchar(400),
     @SortOrder int

SET @FileID = {test value}
SET @CaseID = {test value}
SET @FielName = {test value}
etc., etc.
Random Solutions  
 
programming4us programming4us