Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

error with stored procedure Expand / Collapse
Author
Message
Posted Thursday, December 12, 2013 1:24 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, March 25, 2014 6:07 AM
Points: 8, Visits: 45
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.
Post #1522188
Posted Thursday, December 12, 2013 1:26 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 3:26 AM
Points: 13,724, Visits: 10,679
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?




How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1522190
Posted Thursday, December 12, 2013 5:57 AM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Yesterday @ 4:14 PM
Points: 15,725, Visits: 28,130
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
The Scary DBA
Author of: SQL Server 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans

Product Evangelist for Red Gate Software
Post #1522263
Posted Thursday, December 12, 2013 6:53 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Friday, September 12, 2014 9:43 AM
Points: 7,284, Visits: 13,824
SELECT 
@QTRSTRTDATE = DATEADD(m, DATEDIFF(m, 0, GETDATE()), 0),
@QTRENDDATE = DATEADD(m,DATEDIFF(m,-1, GETDATE()),-1)

EXEC @return_value = [dbo].[test] @QTRSTRTDATE, @QTRENDDATE



“Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

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
Exploring Recursive CTEs by Example Dwain Camps
Post #1522288
Posted Thursday, December 12, 2013 6:59 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 9:23 AM
Points: 12,915, Visits: 32,074
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

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
Post #1522290
Posted Thursday, December 12, 2013 8:08 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Yesterday @ 6:20 AM
Points: 415, Visits: 2,439
Dooooooooooo (12/12/2013)
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.


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 '('.


Post #1522329
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse