Link to home
Create AccountLog in
Avatar of wasabi3689
wasabi3689Flag for United States of America

asked on

Incorrect syntax near the keyword 'CONVERT'.

I create a procedure by using NorthWind database.

Here is my procedure

ALTER PROCEDURE [dbo].[ORDERS_DATA_CURSOR]
@StartDate DateTime, @EndDate DATETIME
AS
DECLARE ORDERS_CURSOR Cursor

FOR
Select CustomerID, OrderDate, ShipName, ShipAddress, ShipCountry
From Orders
where
OrderDate Between @StartDate and @EndDate


Open ORDERS_CURSOR;

DECLARE @CustomerIDVar nvarchar, @OrderDateDate datetime, @ShipNameVar nvarchar, @ShipAddressVar nvarchar, @ShipCountryVar nvarchar
Fetch NEXT FROM ORDERS_CURSOR INTO @CustomerIDVar, @OrderDateDate, @ShipNameVar, @ShipAddressVar, @ShipCountryVar;
While @@FETCH_STATUS = 0
 BEGIN
      Fetch NEXT FROM ORDERS_CURSOR INTO @CustomerIDVar, @OrderDateDate, @ShipNameVar, @ShipAddressVar, @ShipCountryVar;
   END;
CLOSE ORDERS_CURSOR;
DEALLOCATE ORDERS_CURSOR;


When I test the procedure by the following code, it turns out error "Incorrect syntax near the keyword 'CONVERT'." But, I don't find the error

USE [Northwind]
GO

DECLARE      @return_value int

EXEC      @return_value = [dbo].[ORDERS_DATA_CURSOR]
            @StartDate = CONVERT(DATETIME, N'07/04/1996'),
            @EndDate = CONVERT(DATETIME, N'05/23/1997')

SELECT      'Return Value' = @return_value

GO

When I run the following statement, it just works fine to me


Select CustomerID, OrderDate, ShipName, ShipAddress, ShipCountry
From Orders
where
OrderDate Between CONVERT (DATETIME, N'07/04/1996') and CONVERT(DATETIME, N'05/23/1997')

Any one can point out why it turns out with error when I test it.
ASKER CERTIFIED SOLUTION
Avatar of Tony303
Tony303
Flag of New Zealand image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account