Reputation: 45
I have the following table:
And all I want to do is add two new rows per PersonID i.e.
These are just small snip bits from the actual table, as this table contains large amount of data.
Any help would be greatly appreciated.
Upvotes: 0
Views: 95
Reputation: 45
Thanks for everyone's replies/comments.
I managed to resolve my question by using a CURSOR (see below). It's not brilliant but it does the job.
Upvotes: 0
Reputation: 522762
Use INSERT
?
INSERT INTO yourTable (ID, PersonID, JobID, Verified)
SELECT NULL, PersonID, MAX(JobID) + 1, 0
FROM yourTable
GROUP BY PersonID
UNION ALL
SELECT NULL, PersonID, MAX(JobID) + 2, 0
FROM yourTable
GROUP BY PersonID
Explanation:
Inserting NULL
for the ID
column should force the database to assign the next sequence, assuming that ID
be an autoincrement column. If it is not, then maybe consider changing this. For each of the new records, the JobID
sequence is just continued, hence my use of n+1
and n+2
. And you seem to be using zero as the default value of Verified
, so this was hard coded.
Upvotes: 1