Insert into table question

  • I have to create table from select querry

    drop MyNewTable

    SELECT *

    INTO MyNewTable

    FROM top (10)........

    and is very important to create unique identifier ID column in MyNewTable for each record i'm inserting.

    or instead of creating and droping MyNewTable how can I just update MyNewTable with the results from select statement

  • This should work for you.....

    drop MyNewTable

    SELECT IDENTITY(int,1,1) as RowID, t.*

    INTO MyNewTable t

    FROM top (10)........

    If this is in a stored proceudre, I would suggest that you explicitly define the table and then use the INSERT INTO...SELECT FROM construct instead.

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

  • Agree with John - with a few syntax corrections....

    drop table MyNewTable

    SELECT top (10) IDENTITY(int,1,1) as RowID, * --top 10 need to be in the SElect, not the from

    INTO MyNewTable

    FROM ...

    ----------------------------------------------------------------------------------
    Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?

  • Yep, you're correct Matt. My bad....cut and paste error:Whistling: .

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

  • Thank you guys.This answered my question

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply