March 5, 2007 at 7:38 pm
Hello,
Can anybody show me how to do this. I have these tblUser and tblProjectName that will keep on updating whenever there are new users and project names. I want in the tblProjectMembers will also update everytime there are new users and project names has been added. UserID must have all the ProjectID in tblProjectmembers in order to have the rights in all projects. Kindly show me how to make a stored procedure for this one. Thanks in advance.
tblUser
UserId | UserName |
1 | Ab |
2 | Cd |
tblProjectName
ProjectId | ProjName |
1 | Project1 |
2 | Project2 |
3 | Projcet3 |
tblProjectMembers
UserId | ProjectId |
1 | 1 |
1 | 2 |
1 | 3 |
2 | 1 |
2 | 2 |
2 | 3 |
March 5, 2007 at 10:33 pm
I can't really imagine assigning all users to every new project and vice versa... but, if you must, put a trigger on the User and Project tables that does it for you. Each would basically do a cross-join of the INSERTED table with the opposite table.
--Jeff Moden
Change is inevitable... Change for the better is not.
March 5, 2007 at 11:10 pm
Yes, I need to give access all users to all projects so they can have rights to put all their concern in each projects.
I really appreciate if you can show me how to do it. Thanks.
March 6, 2007 at 1:04 am
Hi,
You can try the following code for insert in the user table. Similarly you can do for the project table.
Here is the code...Hope this helps
create trigger usr_update on tbluser after insert
as
declare
@usr_ident smallint
select @usr_ident = @@identity from inserted
insert
into tblProjectMembers ( userid,projectid) select @usr_ident as userid, projectid from tblProjectName
Regards,
March 6, 2007 at 2:06 am
Thanks a lot. It is now working I really appreciate your help. Thanks again.
March 6, 2007 at 6:27 am
Oh, be careful... I could be wrong but I'm thinking that if you have an insert of more than one user, you'll only get one value for @user_ident for that code... it would be better to use the INSERTED table as part of the INSERT in the code above.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply