troubleshooting Question

Convert varchar to a date

Avatar of aneilg
aneilgFlag for United Kingdom of Great Britain and Northern Ireland asked on
SQL
6 Comments2 Solutions238 ViewsLast Modified:
I have a tale that I populate with a select query.

The field in question is called [05_Appt Date] [varchar](50) NULL, 22/12/09
I want to convert the field to a date.

when i test the query i get.
Msg 241, Level 16, State 1, Line 1
Conversion failed when converting datetime from character string.

USE [Reports]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE sp_rpt

	@FromDate DATETIME,
	@ToDate DATETIME

AS

BEGIN

	SELECT

		[03_PCode]	
	,	[04_Name]
	,	CONVERT(DATETIME,[05_Appt Date],103) AS [05_Appt Date]
	,	[07_TYPE]
	,	[09_Address]
	,	[12_email]

	FROM [rptEngineersSchedule]
	WHERE [05_Appt Date]
	BETWEEN @FromDate AND @ToDate	

END
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 2 Answers and 6 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros