csePixelated
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.
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
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
i have run the above without the IDENTITY_INSERT, it comes up (0 row(s) affected)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
i think i have found my mistake, i got the number in the where clause wrong
Yep, that would certainly do it.
ASKER
Thankyou Russ, I really just needed that verification that i had the query correct.
ASKER
so that's why i had added that. mind you i figured out i had messed up and reverted to a backup.