Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Stored Procedure Error SQL 2005

Posted on 2011-03-24
3
Medium Priority
?
232 Views
Last Modified: 2012-05-11
I receive the following error when trying to execute my Stored Procedure.

Error converting data type nvarchar to datetime.

The field in my Table is a datetime. I have placed the query below as well as the code that I am using to execute the query is at the very bottom.
USE [EXPORTHpixPROD]
GO
/****** Object:  StoredProcedure [dbo].[spGetMonthlyEvaluationByEventID]    Script Date: 03/24/2011 07:25:14 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Michael Burk
-- Create date: 03232011
-- Description:	Report that selects Evaluations by EventID and Month
-- =============================================
ALTER PROCEDURE [dbo].[spGetMonthlyEvaluationByEventID] 
	-- Add the parameters for the stored procedure here
	(@EventID AS BIGINT,
	 @FromDate as DATETIME,
	 @ToDate as DATETIME)
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	SELECT DISTINCT    
						CME_Parsed_Survey_XML.SurveyID
					   ,CME_Parsed_Survey_Results_XML.SurveyID
					   ,CME_Parsed_Survey_XML.SurveyDate
					   ,CME_Parsed_Survey_XML.EventID
					   ,CME_Parsed_Survey_XML.LicenseNumber
					   ,CME_Parsed_Survey_Results_XML.QuestionID
					   ,CME_Parsed_Survey_Results_XML.QuestionText
					   ,CME_Parsed_Survey_Results_XML.AnswerTextID
					   ,CME_Parsed_Survey_Results_XML.AnswerText
					   ,CME_Parsed_Survey_Results_XML.AnswerText2
					   ,CME_Parsed_Registration_XML.Designation
					   ,CME_Parsed_Registration_XML.FirstName
					   ,CME_Parsed_Registration_XML.LastName
					   ,CME_Parsed_Registration_XML.Title AS Suffix
					   ,CME_Courses.Title AS Title
					   ,CME_Courses.URL					  
FROM        CME_Parsed_Survey_XML INNER JOIN
			CME_Parsed_Survey_Results_XML ON CME_Parsed_Survey_XML.SurveyID = CME_Parsed_Survey_Results_XML.SurveyID
			INNER JOIN
			CME_Parsed_Registration_XML ON CME_Parsed_Survey_XML.LicenseNumber = CME_Parsed_Registration_XML.MedicalLicenseNumber
			INNER JOIN
			CME_Courses ON CME_Parsed_Survey_XML.EventID = CME_Courses.EventID
WHERE SurveyDate between (@FromDate) and (@ToDate)
END
------------------------------------------------------------------------------------------------
Code to execute query
------------------------------------------------------------------------------------------------
USE [EXPORTHpixPROD]
GO

DECLARE	@return_value int

EXEC	@return_value = [dbo].[spGetMonthlyEvaluationByEventID]
		@EventID = 87895,
		@FromDate = N'02012011',
		@ToDate = N'02312011'

SELECT	'Return Value' = @return_value

GO

Open in new window

0
Comment
Question by:mburk1968
3 Comments
 
LVL 20

Accepted Solution

by:
Rikin Shah earned 1000 total points
ID: 35205955
you need to convert these dates to DateTime while executing


                @FromDate = N'02012011',
                @ToDate = N'02312011'
0
 

Author Comment

by:mburk1968
ID: 35206026
Do you have an example?
0
 
LVL 1

Expert Comment

by:ltmnm
ID: 35207415
Try changing the format of the dates that you are passing in.
from 02012011 to 02/01/2011
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are some very powerful Dynamic Management Views (DMV's) introduced with SQL 2005. The two in particular that we are going to discuss are sys.dm_db_index_usage_stats and sys.dm_db_index_operational_stats.   Recently, I was involved in a di…
by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Screencast - Getting to Know the Pipeline

963 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question