Question: Check if there are any orders before a given date (`Date` column). The procedure has a passing parameter "date" as date and another passing parameter "count". This parameter returns the number of orders before this date.

The simple way of doing it would be:

```
SELECT COUNT([Sales].[dbo].[Order].[Date])
FROM [Sales].[dbo].[Order]
WHERE [Sales].[dbo].[Order].[Date] >= '2019-03-11'

```

But unfortunately I have to use the procedure and the cursor. My attempt is this:

```
CREATE OR ALTER PROCEDURE OrderBeforeDate
    (@date date, 
     @count int OUT)
AS
BEGIN
    SET @count = 0;

    DECLARE cursor1 SCROLL CURSOR FOR
        SELECT [Sales].[dbo].[Order].[Date] 
        FROM [Sales].[dbo].[Order]
        FOR READ ONLY

    OPEN cursor1;

    FETCH NEXT FROM cursor1 INTO @date

    WHILE @@FETCH_STATUS = 0
    BEGIN
        IF @date <= '2019-03-11'
            SET @count = @count + 1;
    END

    CLOSE cursor1;
    DEALLOCATE cursor1;
END

DECLARE @count int

EXEC OrderBeforeDate @count OUT

PRINT 'Number of Orders after 2019-03-11'': ' + CAST(@count AS VARCHAR(10))

```

But I get the following error message:

> 
> Operand type collision: int is incompatible with date
> 
> 
> 

I don't know what to do. Please give me a helping hand.

Answer: 
You are not passing the expected parameters. In your mock-up I would expect to see

```
DECLARE @count int=0, @Date date='20190311'

EXEC OrderBeforeDate @Date, @count OUT

PRINT 'Number of Orders after 2019-03-11: ' + CAST(@count AS VARCHAR(10))

```

I would also point out (as you presumably already know) this cursor serves no purpose other than to put the brakes on SQL Server performance.

Also your procedure is counting rows *before* your date value, your `print` statement states the opposite.
Yor stored procedure expects 2 parameters while you pro ide only one. Date parameter is missing.
Your cursor has infinite loop and yoyr procedure will never end

Using a cursor for this is a verry bad idea, put your count in the sored procedure