December 12, 2013 at 1:24 am
when i execute the SP with data parameters
USE [ABC]
GO
DECLARE@return_value int
EXEC@return_value = [dbo].[test]
@QTRSTRTDATE = N'select CONVERT(datetime,DATEADD("M", DATEDIFF("M", 0, GETDATE()), 0),120)',
@QTRENDDATE = N'select CONVERT(datetime,DATEADD("M",DATEDIFF("M",-1, GETDATE()),-1),120)'
SELECT'Return Value' = @return_value
GO
i get the below error..
Msg 8114, Level 16, State 5, Procedure usp_MarketingAccountLevel_test, Line 0
Error converting data type nvarchar to datetime.
(1 row(s) affected)
Any help.
December 12, 2013 at 1:26 am
It would probably be useful to see what the stored procedure actually does.
Any reason you pass dates converted to strings as parameters instead of the actual dates?
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
December 12, 2013 at 5:57 am
It's got to be because of the conversion of the dates to strings. Just leave them as dates. Use date math and date comparisons within T-SQL. They work. String manipulation instead of using core data types frequently leads to problems.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
December 12, 2013 at 6:53 am
SELECT
@QTRSTRTDATE = DATEADD(m, DATEDIFF(m, 0, GETDATE()), 0),
@QTRENDDATE = DATEADD(m,DATEDIFF(m,-1, GETDATE()),-1)
EXEC @return_value = [dbo].[test] @QTRSTRTDATE, @QTRENDDATE
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
December 12, 2013 at 6:59 am
in the procedure itself, do you have something like RETURN @MyDateValue
the return of a stored procedure only can return an integer, and it typically means success(0) or failure(non zero) , like an error number.
maybe you want to capture the resuts of the procedure instead? have it SELECT @MyDateValue
Lowell
December 12, 2013 at 8:08 am
Dooooooooooo (12/12/2013)
when i execute the SP with data parametersUSE [ABC]
GO
DECLARE@return_value int
EXEC@return_value = [dbo].[test]
@QTRSTRTDATE = N'select CONVERT(datetime,DATEADD("M", DATEDIFF("M", 0, GETDATE()), 0),120)',
@QTRENDDATE = N'select CONVERT(datetime,DATEADD("M",DATEDIFF("M",-1, GETDATE()),-1),120)'
SELECT'Return Value' = @return_value
GO
i get the below error..
Msg 8114, Level 16, State 5, Procedure usp_MarketingAccountLevel_test, Line 0
Error converting data type nvarchar to datetime.
(1 row(s) affected)
Any help.
You're passing in strings (nvarchar), most likely, inside your procedure you've defined the parameters as datetime. It seems like you're expecting these to be evaluated and then passed, but I haven't had any luck passing an expression as a parameter to a stored procedure.
CREATE PROCEDURE [dbo].[TEST]
@TESTPARAM INT
AS
BEGIN
SELECT @TESTPARAM
END
...
DECLARE @rc int
DECLARE @TESTPARAM int
-- TODO: Set parameter values here.
EXECUTE @rc = [dbo].[TEST]
@TESTPARAM=N'SELECT 1'
GO
Msg 8114, Level 16, State 4, Procedure TEST, Line 0
Error converting data type nvarchar to int.
DECLARE @rc int
DECLARE @TESTPARAM int
-- TODO: Set parameter values here.
EXECUTE @rc = [dbo].[TEST]
@TESTPARAM=(1+1)
GO
Msg 170, Level 15, State 1, Line 8
Line 8: Incorrect syntax near '('.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply