Professional Web Applications Themes

Copy data into same table - Microsoft SQL / MS SQL Server

I have table Properties. I want to select data for one item and to add that data in same table but for other item (all values would be the same only value of item would change). Can somebody suggest SQL statement for that? Thank you....

  1. #1

    Default Copy data into same table

    I have table Properties.



    I want to select data for one item and to add that data in same table but
    for other item (all values would be the same only value of item would
    change).

    Can somebody suggest SQL statement for that?



    Thank you.



    Johny Guest

  2. #2

    Default Re: Copy data into same table

    Do you mean

    insert MyTab1 (Col2, Col3)
    select Col2, 1
    from MyTab1

    What is the value that you want in the column that is different in the
    inserted records and which one is it?

    Nigel Rivett (SQL Server MVP)
    [url]www.nigelrivett.net[/url]

    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    Nigel Rivett Guest

  3. #3

    Default Re: Copy data into same table

    I have table Properties



    ID
    Value1
    Value2
    Value3

    1111
    1
    2
    3

    1111
    4
    5
    6

    1111
    7
    8
    9




    I want to add new rows in table, so that I copy every row where ID = 1111 and only change ID



    ID
    Value1
    Value2
    Value3

    1111
    1
    2
    3

    1111
    4
    5
    6

    1111
    7
    8
    9

    2222
    1
    2
    3

    2222
    4
    5
    6

    2222
    7
    8
    9




    I know some solution for that. For example I can create view and than update ID and that Insert records from that view.

    Maybe there is more simple solution.

    Johny Guest

  4. #4

    Default Re: Copy data into same table

    Hi

    If you want to insert the new rows then

    INSERT INTO MyTable ( ID, Value1, Value2, Value3 ) SELECT 2222, Value1, Value2, Value3 FROM MyTable WHERE ID = 1111

    will add the new rows.

    Alternatively if you just want to select two lots of values then

    SELECT ID, Value1, Value2, Value3 FROM MyTable WHERE ID = 1111
    UNION ALL
    SELECT 2222, Value1, Value2, Value3 FROM MyTable WHERE ID = 1111

    HTH


    John
    "Johny" <com> wrote in message news:phx.gbl...
    I have table Properties



    ID
    Value1
    Value2
    Value3

    1111
    1
    2
    3

    1111
    4
    5
    6

    1111
    7
    8
    9




    I want to add new rows in table, so that I copy every row where ID = 1111 and only change ID



    ID
    Value1
    Value2
    Value3

    1111
    1
    2
    3

    1111
    4
    5
    6

    1111
    7
    8
    9

    2222
    1
    2
    3

    2222
    4
    5
    6

    2222
    7
    8
    9




    I know some solution for that. For example I can create view and than update ID and that Insert records from that view.

    Maybe there is more simple solution.

    John Guest

  5. #5

    Default Re: Copy data into same table

    Thank you.
    "John Bell" <com> wrote in message news:3f1166f9$0$18749$easynet.co.uk...
    Hi

    If you want to insert the new rows then

    INSERT INTO MyTable ( ID, Value1, Value2, Value3 ) SELECT 2222, Value1, Value2, Value3 FROM MyTable WHERE ID = 1111

    will add the new rows.

    Alternatively if you just want to select two lots of values then

    SELECT ID, Value1, Value2, Value3 FROM MyTable WHERE ID = 1111
    UNION ALL
    SELECT 2222, Value1, Value2, Value3 FROM MyTable WHERE ID = 1111

    HTH


    John

    Johny Guest

Similar Threads

  1. Replies: 0
    Last Post: June 1st, 03:15 AM
  2. Replies: 4
    Last Post: October 27th, 03:01 PM
  3. copy table
    By xixi in forum Coldfusion Database Access
    Replies: 1
    Last Post: February 17th, 08:11 AM
  4. How to get Table Parameters to copy table
    By Joe in forum ASP Database
    Replies: 5
    Last Post: November 29th, 12:13 AM
  5. Copy data from one table to another
    By Allan Mitchell in forum Microsoft SQL / MS SQL Server
    Replies: 0
    Last Post: July 4th, 01:01 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139