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
 General SQL Server Forums
 New to SQL Server Programming
 how to insert null values basing on count ???

Author  Topic 

mohan123
Constraint Violating Yak Guru

252 Posts

Posted - 2013-01-03 : 08:04:44
i have a table A

in which data look like this

userid documentid name
1 1 mohan

1 2 raj

1 3 majuu

2 1 raj

2 2 jey

2 3 lol

so we can observe user id 1 have 3 document id(1,2,3) so how to insert 4 and 5 records when userID 1 have 3 records if it have 3 rd record inserted simultaneously 4 and 5 th record should inserted through procedure can any one suggest me ???

P.V.P.MOhan

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2013-01-03 : 08:27:43
How are the rows inserted?
Do you mean if there is an insert for a user id that has 2 roes then you want an extra two added?

Obvious options are
Insert via a stored procedure, count the rows then insert the extra 2 if there are 3 rows. It will need to be in a transaction.
Create a trigger for insert. If the count is 3 for the user then add the extra 2 rows.


==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -