Select *, except...

  • Hi everyone,

    I'm writing a SPROC to clone rows in tables, but with different primary keys. For example,

    create table #temp(

    myId int primary key,

    value1 varchar(50),

    value2 varchar(50)

    )

    insert into #temp

    select 1, 'ThisIsA', 'Test' UNION

    select 2, 'Garbage', 'Data'

    Now when I go to select the record I want to use to clone, I was wondering if there is a way to select all the data from the table except the primary key, akin to

    INSERT into #temp

    SELECT @NewID, * (but not myID) From #TEMP Where myId = @OldID

    My real table has 40 some fields and I don't want to write a query that's 7 lines long.

    Maybe i'm just lazy :doze:

    ---
    Dlongnecker

  • I'd go with the lazy, as there is no way to do that.

    I don't know if this works in SQL 2000 QA, but in SSMS you can drag the columns from the Obkect Browser into the Query window.

  • Yes, in QA you can drag the columns to the query window. Drag and drop the columns folder from the object explorer in QA to the query window.

    😎

  • Use QA to generate the statement, but you'll still need to long query.

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

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