Link to home
Start Free TrialLog in
Avatar of csePixelated
csePixelatedFlag for United States of America

asked on

Append to SQL table, duplicate lines already in SQL table

i have a simple 3 field sql table
ID , ID_AutoReport , Limit

ID is (PK, Int, not null)
ID_AutoReport is (int, null)
Limit is (nvchar(200), not null)

i need a simple sql query to add new rows with new IDs the number of rows i will be adding will be equal to the number of entries for  ID_AutoReport that match 349730 , and will duplicate the data in the Limit field. (I hope I haven't made this confusing)
i think i've gotten myself a little confused as to the way parts of my query relate to the data i am replicating.

SET IDENTITY_INSERT DAAutoReportsLimit ON;

INSERT INTO [SYSTEM SETUP].dbo.[DAAutoReportsLimit] ( 
                                 ID_AutoReport ,
                                 Limit )
            SELECT 
                   350163 ,
                   Limit
            FROM   [SYSTEM SETUP].dbo.[DAAutoReportsLimit]
            WHERE  ID_AutoReport = 349730;
SET IDENTITY_INSERT DAAutoReportsLimit OFF

Open in new window


example:
table before:
ID , ID_AutoReport , Limit
1,349730,555-555-1234
2,349730,555-555-4321
3,349730,bob@gmail.com
4,349731,tom@elseware.net

table after:
1,349730,555-555-1234
2,349730,555-555-4321
3,349730,bob@gmail.com
4,349731,tom@elseware.net
5,350163,555-555-1234
6,350163,555-555-4321
7,350163,bob@gmail.com
SOLUTION
Avatar of Russ Suter
Russ Suter

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of csePixelated

ASKER

yes, so i will remove the IDENTITY_INSERT, when i first started i thought the number i had to duplicate was the ID not the ID_AutoReport.
so that's why i had added that. mind you i figured out i had messed up and reverted to a backup.
i have run the above without the IDENTITY_INSERT, it comes up (0 row(s) affected)
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
i think i have found my mistake, i got the number in the where clause wrong
Avatar of Russ Suter
Russ Suter

Yep, that would certainly do it.
Thankyou Russ, I really just needed that verification that i had the query correct.