SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 date format
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

peace
Constraint Violating Yak Guru

404 Posts

Posted - 04/22/2013 :  10:58:39  Show Profile  Reply with Quote
Hi, I already convert the format to date but still getting this error:

Conversion failed when converting date and/or time from character string.

Select convert(date,createdDate) Date .....

jackv
Flowing Fount of Yak Knowledge

United Kingdom
2023 Posts

Posted - 04/22/2013 :  11:04:08  Show Profile  Visit jackv's Homepage  Reply with Quote
What is the input CreatedDate , could you post . Here is an example of a data convert
Select CONVERT(Date, '13-5-2012', 101)

Read more on msdn http://msdn.microsoft.com/en-us/library/ms187928.aspx

Jack Vamvas
--------------------
http://www.sqlserver-dba.com
Go to Top of Page

peace
Constraint Violating Yak Guru

404 Posts

Posted - 04/22/2013 :  11:08:27  Show Profile  Reply with Quote
the input date is

2011-12-31
Go to Top of Page

James K
Flowing Fount of Yak Knowledge

3578 Posts

Posted - 04/22/2013 :  11:12:03  Show Profile  Reply with Quote
It may be that there are some rows in your table that are invalid. You can find them using this:
select * from yourTable where isdate(createdDate) = 0;
Go to Top of Page

peace
Constraint Violating Yak Guru

404 Posts

Posted - 04/22/2013 :  11:24:09  Show Profile  Reply with Quote
when i run select manually it works but it doesn't works when i union all together.

Select *
From (
Select * From #0
UNION ALL
Select * From #1
UNION ALL
Select * From #2
) A
Go to Top of Page

jackv
Flowing Fount of Yak Knowledge

United Kingdom
2023 Posts

Posted - 04/22/2013 :  11:24:37  Show Profile  Visit jackv's Homepage  Reply with Quote
you could think about changing the dateformat
select CONVERT(Date, '2011-12-31', 101)

to the ISO format

select CONVERT(Date, '20111231', 101)


Jack Vamvas
--------------------
http://www.sqlserver-dba.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000