Syed Muhammad Ahmad
Syed Muhammad Ahmad

Reputation: 438

Msg 102, Level 15, State 1, Line 9 Incorrect syntax near '-'

I have created a stored procedure successfully. When I execute this procedure by passing parameters it throws the following exception:

Msg 102, Level 15, State 1, Line 9
Incorrect syntax near '-'

USE [master]
 GO

    DECLARE @return_value int

    EXEC    @return_value = [dbo].[spJobsGet]
    @Email = N'[email protected]',
    @Password = N'password',
    @JobSheetID = 0,
    @PropertyID = 0,
    @DateFrom = 2014-06-20,
    @DateTo = 2014-07-20

    SELECT  'Return Value' = @return_value

    GO

I am stuck. Please help.

Upvotes: 2

Views: 8142

Answers (2)

Vahid Farahmandian
Vahid Farahmandian

Reputation: 6566

You should put parameters with datatype character or datetime or etc inside the quotes. So try this:

USE [master]
GO

DECLARE @return_value int

EXEC    @return_value = [dbo].[spJobsGet]
@Email = N'[email protected]',
@Password = N'password',
@JobSheetID = 0,
@PropertyID = 0,
@DateFrom = '2014-06-20',
@DateTo = '2014-07-20'

SELECT  'Return Value' = @return_value

GO

Upvotes: 0

Liesel
Liesel

Reputation: 2979

You need to put quotes around your date string literals:

@DateFrom = '2014-06-20', 
@DateTo = '2014-07-20'

You should be aware that the format you are using can be ambiguous, a better option would be

@DateFrom = '20140620', 
@DateTo = '20140720'

which is always interpreted as YYYYMMDD.

https://technet.microsoft.com/en-us/library/ms180878.aspx#UnseparatedStringFormat

Upvotes: 2

Related Questions