Link to home
Start Free TrialLog in
Avatar of asrisbey
asrisbey

asked on

SQL 2005 SELECT statement - simple datetime issue

This is a really simple syntax issue. I have the following select statement:

SELECT dbo.CONTENT_Event.eventID, dbo.CONTENT_Event.EventName + ' (' + EventOrgName + ')' + EventDate

which returns the following error:

Conversion failed when converting datetime from character string.

All I want to know is the correct syntax for returning the date only from the EventDate datetime field in dd/mm/yyyy format. By the way, I'm restricted to returning 2 columns of data, hence the select statement format.

Thanks for any help.
Avatar of Ashish Patel
Ashish Patel
Flag of India image

Try this.

SELECT dbo.CONTENT_Event.eventID, dbo.CONTENT_Event.EventName + ' (' + EventOrgName + ')' + Cast(EventDate as varchar)
try this
SELECT dbo.CONTENT_Event.eventID, dbo.CONTENT_Event.EventName + 
' (' + EventOrgName + ')' + convert(varchar,EventDate,103)

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Ashish Patel
Ashish Patel
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of f_o_o_k_y
You should use convert

example:

SELECT dbo.CONTENT_Event.eventID, dbo.CONTENT_Event.EventName + ' (' + EventOrgName + ')' + Convert(varchar(10), EventDate, 103)
Avatar of asrisbey
asrisbey

ASKER

I knew it would be easy! Thanks, works a treat.