TheNewone
TheNewone

Reputation: 97

Rowcount in SQL not returning the correct count

I have a stored procedure as shown below in which I am trying to get row count based on some condition. My problem is that I get all the records no regards to conditions.

Here is my latest attempt:

ALTER PROCEDURE [dbo].[checkForTaskTodoToday]
    @bruger VARCHAR(250)
AS
BEGIN
    SELECT daysLeft 
    FROM Todolist
    WHERE daysLeft = 0 
      AND Bruger = @bruger 
      AND udført = 0 

    RETURN @@rowcount
END

When I run the code from Management Studio, it returns the correct number.

What am I doing wrong?

Upvotes: 0

Views: 452

Answers (1)

Ankur Patel
Ankur Patel

Reputation: 1423

I am not sure why the @@rowcount is not working but maybe you can try the following. This will give you the count of record that you need.

ALTER PROCEDURE [dbo].[checkForTaskTodoToday]
@bruger varchar(250)
AS
begin
select Count(*) from Todolist
where daysLeft=0 and Bruger = @bruger and udført = 0 
END

Upvotes: 1

Related Questions