November 23, 2006 at 3:54 pm
Hi,
I'm trying to insert records from one table into another table. The destination table has a ROWID field which cannot be an identity key, but needs to 'act like' an identity key and have its value populated with (Max(ROWID) + 1) for each row added to the table.
To my thinking, simply using (Max(ROWID) + 1) in my SELECT statement will not work as it will only be evaluated once so if I am adding 1000 records and Max(ROWID) is 1234, all 1000 entries will end up having a ROWID of 1235.
Is there a way to accomplish this?
Thanks
November 23, 2006 at 5:41 pm
Create #Table with IDENTITY column, populate it with new data and than insert from #Table to destination table with Max(ROWID) + #Table.ID
_____________
Code for TallyGenerator
November 24, 2006 at 4:22 pm
The destination table has a ROWID field which cannot be an identity key, ...
Why the heck not?
--Jeff Moden
Change is inevitable... Change for the better is not.
November 28, 2006 at 10:52 pm
use a correleated subquery
for instance:
id | grouping
select grouping, (select count (*) from table b where b.id < a.id and a.grouping = b.grouping)
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply