Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Add multiple records

Author  Topic 

waleed
Starting Member

2 Posts

Posted - 2012-04-12 : 10:27:48
Hello
I have a problem to add a recordset from a table to another table and this table contains a field that I want to start a new serial number for each line
How can I add a new number by adding multiple records
I use this code for the process added


INSERT  INTO dbo.Items
( ItemID ,
ItemCode ,
ItemName
)
SELECT ( SELECT MAX(ItemID + 1)
FROM dbo.Items
) ,
ItemCode ,
ItemName
FROM dbo.View_TestAddCom


The result

114345 10101-11A88 GASKET K ENG RE
114345 10101-11E85 GASKET-ENGINE
114345 10101-11M87 GSKT KIT ENG
114345 10101-12E25 GASKET-ENGINE
114345 10101-13E25 GASKET ENG REP
114345 10101-13E26 GASKET-ENGINE
114345 10101-13E85 GASKET-ENGINE
114345 10101-14A25 GAKET ENG
114345 10101-15B86 GASKET-ENGINE




Thank you in advance

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2012-04-12 : 11:04:15
SELECT ( SELECT MAX(ItemID)
+ ROW_NUMBER() OVER(Order BY itemID)
FROM dbo.Items
)
,
ItemCode ,
ItemName
FROM dbo.View_TestAddCom

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

waleed
Starting Member

2 Posts

Posted - 2012-04-12 : 13:59:32
Thanks for the help but it did not work
Go to Top of Page
   

- Advertisement -