How to insert row using another name

  • Hello:

    I have table1 who has fields: name, dd

    I want to insert new name: Jenny, but use value of name: Rack

    select * from table1 where name = 'Rack'

    Name dd

    Rack 2

    Rack 4

    Rack 1

    Rack 33

    Rack 44

    I want insert Jenny to table1 and use Rack's dd value

    Name dd

    Jenny 2

    Jenny 4

    Jenny 1

    Jenny 33

    Jenny 44

    How to accomplish it?

    Your help is highly appreciated.

  • Something like below?

    CREATE TABLE #table1

    (

    name varchar(10),

    dd int

    )

    INSERT INTO #table1

    SELECT 'Rack', 2 UNION ALL

    SELECT 'Rack', 4 UNION ALL

    SELECT 'Rack', 1 UNION ALL

    SELECT 'Rack', 33 UNION ALL

    SELECT 'Rack', 44

    INSERT INTO #table1

    SELECT 'Jenny', t.dd

    FROM #table1 t

    WHERE t.name = 'Rack'

    SELECT name, dd FROM #table1

  • Yes. Thank you very much!

  • this is also an option

    INSERT INTO #table1

    SELECT REPLACE('Jenny','Rack',name),dd

    FROM #table1

    Bob
    -----------------------------------------------------------------------------
    How to post to get the best help[/url]

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

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