SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


error with stored procedure


error with stored procedure

Author
Message
Dooooooooooo
Dooooooooooo
Valued Member
Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)

Group: General Forum Members
Points: 50 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.
Koen Verbeeck
Koen Verbeeck
SSC Guru
SSC Guru (60K reputation)SSC Guru (60K reputation)SSC Guru (60K reputation)SSC Guru (60K reputation)SSC Guru (60K reputation)SSC Guru (60K reputation)SSC Guru (60K reputation)SSC Guru (60K reputation)

Group: General Forum Members
Points: 60863 Visits: 13297
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?
My blog at SQLKover.

MCSE Business Intelligence - Microsoft Data Platform MVP
Grant Fritchey
Grant Fritchey
SSC Guru
SSC Guru (96K reputation)SSC Guru (96K reputation)SSC Guru (96K reputation)SSC Guru (96K reputation)SSC Guru (96K reputation)SSC Guru (96K reputation)SSC Guru (96K reputation)SSC Guru (96K reputation)

Group: General Forum Members
Points: 96235 Visits: 33013
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 Query Performance Tuning and SQL Server Execution Plans
Product Evangelist for Red Gate Software
ChrisM@Work
ChrisM@Work
SSC-Forever
SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)

Group: General Forum Members
Points: 40420 Visits: 20000
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
Lowell
Lowell
SSC Guru
SSC Guru (69K reputation)SSC Guru (69K reputation)SSC Guru (69K reputation)SSC Guru (69K reputation)SSC Guru (69K reputation)SSC Guru (69K reputation)SSC Guru (69K reputation)SSC Guru (69K reputation)

Group: General Forum Members
Points: 69822 Visits: 40918
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
--help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!
patrickmcginnis59 10839
patrickmcginnis59 10839
SSCarpal Tunnel
SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)

Group: General Forum Members
Points: 4232 Visits: 5893
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 '('.




to properly post on a forum:
http://www.sqlservercentral.com/articles/61537/
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search