SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 how to insert null values basing on count ???
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

mohan123
Constraint Violating Yak Guru

India
252 Posts

Posted - 01/03/2013 :  08:04:44  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

United Kingdom
3383 Posts

Posted - 01/03/2013 :  08:27:43  Show Profile  Visit nigelrivett's Homepage  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000