August 25, 2005 at 1:13 pm
I have two SQL Server tables which have an identical column complement except table2 has one additional column. I want to insert a row from table1 into table2. The additional column to be populated in table2 is a datetime with a default value.
I have been trying to use INSERT...SELECT but I keep getting unequal column count errors.
Can anybody help????
INSERT INTO CumulativeTable (field1, field2, extrafield)
SELECT field1, field2
from CurrentTable
August 25, 2005 at 1:14 pm
Can you post the statement please?
August 25, 2005 at 1:32 pm
INSERT INTO CumulativeTable (field1, field2, extrafield)
SELECT field1, field2, extrafield from sometable
or SELECT field1, field2, null
or
INSERT INTO CumulativeTable (field1, field2, extrafield)
SELECT field1, field2
the count of fields to insert must be the same as the fields selected.
Lowell
August 25, 2005 at 1:35 pm
I meant in a new message .
This solution is the best in your case (ignore the extra field in the insert) :
INSERT INTO CumulativeTable (field1, field2)
SELECT field1, field2
August 25, 2005 at 3:06 pm
Remi's and Lowell's solutions are good, then your extra field will get populated with nulls (if allowed). If nulls are not allowed, then you need to supply a value in your insert, or set a default value for that field.
August 25, 2005 at 3:14 pm
"The additional column to be populated in table2 is a datetime with a default value."
August 26, 2005 at 8:31 am
Oh yeah, I knew that !! D'oh !!
August 26, 2005 at 8:34 am
Hey we found who Homer Simpson is .
August 26, 2005 at 12:56 pm
I also have a "smarty pants" daughter and a "smart ass" son ...... A little too much like Lisa & Bart ..... At least I like "good" beer, not any old stuff like Duff
August 26, 2005 at 12:58 pm
God I'd like to see a picture of that .
August 26, 2005 at 1:13 pm
Here ya go
August 26, 2005 at 1:18 pm
I meant a real pic... but thanx for the link .
August 26, 2005 at 1:27 pm
Or did you mean a picture of my kids ? They don't look quite like the Simpsons, but act like them sometimes.
Viewing 13 posts - 1 through 13 (of 13 total)
You must be logged in to reply to this topic. Login to reply