Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Insert data from one table to another

Author  Topic 

PeeJay2583
Starting Member

40 Posts

Posted - 2011-05-12 : 10:37:00
Hi,

I am trying to insert data from one table to another however getting an error message "Msg 241, Level 16, State 1, Line 1
Conversion failed when converting datetime from character string."

I have checked the datatype is the same in both the tables also number of fields are matching, don't understand where the problem is occuring.

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-05-12 : 10:41:38
You must be wrong.
If source and destination column both of datatype datetime then this error cannot happen.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

lionofdezert
Aged Yak Warrior

885 Posts

Posted - 2011-05-12 : 10:42:08
Does target and source columns order is same??

--------------------------
http://connectsql.blogspot.com/
Go to Top of Page

PeeJay2583
Starting Member

40 Posts

Posted - 2011-05-12 : 10:49:26
You were right webfred. got the error now. thanks!

Mukesh Sajjan
Go to Top of Page

PeeJay2583
Starting Member

40 Posts

Posted - 2011-05-12 : 10:51:35
One question......

I have one field as datetime in one table and other table doesn't have same field so I am putting as 'na' in that field therefore its giving me the above error message. how can i correct this?
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-05-12 : 10:54:22
Try to replace 'na' by NULL (without single quotes)
If that doesn't help then please show us the create table statements and your query so far.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

PeeJay2583
Starting Member

40 Posts

Posted - 2011-05-12 : 11:00:49
It works webfred. you are a star!

Mukesh Sajjan
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-05-16 : 09:19:35
Note that empty string on datetime column will default to 19000101

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2011-05-16 : 11:45:16
as a best practice, ALWAYS list out the columns

INSERT INTO myTable (Col1, Col2, Col3, Coletc)
SELECT Col1, Col2, Co9l3, Coletc
FROM otherTable
WHERE....

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page
   

- Advertisement -