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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Converting Datetime error
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

CleverRainbow
Starting Member

3 Posts

Posted - 06/01/2012 :  00:27:49  Show Profile  Reply with Quote
This is really bugging me, I keep receiving this error: 'Conversion failed when converting datetime from character string.'

SET DATEFORMAT dmy
INSERT INTO Member
VALUES (1000019,'Evan','Bevan','7/1/1991 0:00:00','12 Green St.','Gold Coast','Queensland',4217,'(07)55734516',0413-111112,'75896C',8/7/2000 0:00:00,0,1,'aaaaas')
GO


This is how i've created the table. The first date is DOB, the second is join date in that order. I believe the error has something to do with 'DEFAULT GETDATE()'?

CREATE TABLE Member (
DOB DATETIME NOT NULL,
JoinDate DATETIME DEFAULT GETDATE(),

visakh16
Very Important crosS Applying yaK Herder

India
47040 Posts

Posted - 06/01/2012 :  00:40:20  Show Profile  Reply with Quote
always try to pass date values in unambiguos iso format

see

http://visakhm.blogspot.com/2011/12/why-iso-format-is-recommended-while.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
47040 Posts

Posted - 06/01/2012 :  00:41:48  Show Profile  Reply with Quote
Also your values are not in same order as your column definition. in that case add an explicit column list in INSERT

INSERT INTO Member (Field1Name,Field2Name,...)
VALUES (1000019,'Evan','Bevan','7/1/1991 0:00:00','12 Green St.','Gold Coast','Queensland',4217,'(07)55734516',0413-111112,'75896C',8/7/2000 0:00:00,0,1,'aaaaas')
GO


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

CleverRainbow
Starting Member

3 Posts

Posted - 06/01/2012 :  01:02:43  Show Profile  Reply with Quote
Ah, thank you very much! I added a column list and it worked perfectly.
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.05 seconds. Powered By: Snitz Forums 2000