DebHanleyRI
Programmer
I am hoping someone can help me - I need to add 2 days to a date - the data comes in like '20100730'.
Has anyone used dateadd in a stored procedure before?
I have the following in a stored procedure:
-------------------------------------------------
ALTER proc [dbo].[psp_RecondoDate]
@inDate datetime
AS
declare @outdate datetime
SET @outdate = DATEADD(d,2,@inDate)
RETURN @outDate
-------------------------------------------------
with the above I get the error:
Msg 257, Level 16, State 3, Procedure psp_RecondoDate, Line 20
Implicit conversion from data type datetime to int is not allowed. Use the CONVERT function to run this query.
If I switch to convert:
--------------------------------------------------------
ALTER proc [dbo].[psp_RecondoDate]
@inDate datetime
AS
--declare @inDate2 datetime
--Set @inDate = '07/14/2010'
--print @indate2
declare @outdate datetime
--SET @outdate = DATEADD(d,2,@inDate)
SET @outdate = convert(@inDate, convert(char(8), dateadd(day, 2, @inDate), 108))
RETURN @outDate
-------------------------------------------------
I get the error:
Msg 102, Level 15, State 1, Procedure psp_RecondoDate, Line 19
Incorrect syntax near '@inDate'.
not all who wander are lost....
Has anyone used dateadd in a stored procedure before?
I have the following in a stored procedure:
-------------------------------------------------
ALTER proc [dbo].[psp_RecondoDate]
@inDate datetime
AS
declare @outdate datetime
SET @outdate = DATEADD(d,2,@inDate)
RETURN @outDate
-------------------------------------------------
with the above I get the error:
Msg 257, Level 16, State 3, Procedure psp_RecondoDate, Line 20
Implicit conversion from data type datetime to int is not allowed. Use the CONVERT function to run this query.
If I switch to convert:
--------------------------------------------------------
ALTER proc [dbo].[psp_RecondoDate]
@inDate datetime
AS
--declare @inDate2 datetime
--Set @inDate = '07/14/2010'
--print @indate2
declare @outdate datetime
--SET @outdate = DATEADD(d,2,@inDate)
SET @outdate = convert(@inDate, convert(char(8), dateadd(day, 2, @inDate), 108))
RETURN @outDate
-------------------------------------------------
I get the error:
Msg 102, Level 15, State 1, Procedure psp_RecondoDate, Line 19
Incorrect syntax near '@inDate'.
not all who wander are lost....