How to add a row to a table

  • 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

  • Can you post the statement please?

  • 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


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • 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

  • 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.

  • "The additional column to be populated in table2 is a datetime with a default value."

  • Oh yeah, I knew that !!    D'oh  !!

  • Hey we found who Homer Simpson is .

  • 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

  • God I'd like to see a picture of that .

  •  

    Here ya go

    Homer Simson doh! pictures

  • I meant a real pic... but thanx for the link .

  • English Pale AleIndia Pale Ale

  • Characterized by intense hop bitterness with a high alcohol content.
  • A high hopping rate and the use of water with high mineral content results in a crisp, dry beer.
  • Golden- to deep-copper-colored ale with a full, flowery hop aroma and may have a strong hop flavor (in addition to the hop bitterness).
  •  

    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