I have successfully created a stored procedure using two input parameters and two output parameters. when I executed this procedure, I'm getting an error
Incorrect syntax near '-'
near the first parameter.
ALTER PROCEDURE [dbo].[Agent_interactions_report]
(
@StartDate date,
@EndDate date,
@ERRORCODE AS INT OUTPUT,
@ERRORDESCRIPTION AS VARCHAR(4000) OUTPUT
)
AS
BEGIN
SET NOCOUNT ON;
begin Try
select
cast([CallStartTime] as Date) as Date,
[AgentID] as [Agent ID], [Agent_Name] as [Agent name],
[CustomerID] as [Cust-ID], [Account_Number] as [Account number],
[Transaction_Des] as [Transaction],
CallStartTime AS [Call start time],
CallEndTime AS [Call end time], CallID as [Call ID]
from
[TBL_AGENT_TRANSACTIONS]
where
cast(CallStartTime as DATE) >= @StartDate
and cast(CallEndTime as Date) <= @EndDate
end Try
begin catch
SET @ERRORCODE = ERROR_NUMBER()
SET @ERRORDESCRIPTION = ERROR_MESSAGE()
end catch
END
This is the executed result:
DECLARE @return_value int,
@ERRORCODE int,
@ERRORDESCRIPTION varchar(4000)
EXEC @return_value = [dbo].[Agent_interactions_report]
@StartDate = 2015-04-27,
@EndDate = 2015-04-27,
@ERRORCODE = @ERRORCODE OUTPUT,
@ERRORDESCRIPTION = @ERRORDESCRIPTION OUTPUT
SELECT @ERRORCODE as N'@ERRORCODE',
@ERRORDESCRIPTION as N'@ERRORDESCRIPTION'
I'm getting error near "@StartDate = 2015-04-27," but when I executed the SP manually by giving this inputs to the input parameters i'm getting the expected result.
Note:
Since my reputation is below 10 i'm not supposed to upload screenshot which will be more useful to understand the issue. Please let me know if you need more info.
@StartDate = '2015-04-27'
, – ughai'2015-04-27'
is a string which will be converted to date when passed to a date variable. Another option is to useDECLARE @dt DATE = DATEFROMPARTS(2015,04,27)
and then use@dt
in yourexec
like@StartDate =@dt
– ughai