| 
                
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. 
    
        | 
                
                    | 
                            
                                | Author | Topic |  
                                    | amodiYak Posting Veteran
 
 
                                        83 Posts | 
                                            
                                            |  Posted - 2009-06-09 : 02:01:45 
 |  
                                            | Hello friends,I have four tables EmployeeTable, DepartmentTable, MessageTable and EmployeeMessageTable.EmployeeTable:EmployeeIdFK_DepartmentId --Relationship with PK_DepartmentId column of DepartmentTable.DepartmentTable:PK_DepartmentIdDepartmentNameMessageTable:PK_MessageIdMessageEmployeeMessageTable:EmployeeIdFk_MessageId – Relationship with PK_MessageId column of MessageTable.I want to write a insert query that will take DepartmentId say “1” and MessageId say “35” as input. If department “1” contains 10 employees then query should insert 10 records in “EmployeeMessageTable” as:Insert into EmployeeMessageTable(EmployeeId,fk_MessageId) values(“Emp_1_department_1”,35)Insert into EmployeeMessageTable(EmployeeId,fk_MessageId) values(“Emp_2_department_1”,35)……Insert into EmployeeMessageTable(EmployeeId,fk_MessageId) values(“Emp_10_department_1”,35)Query or stored procedure example would be helpful.Thanks.No paiN No gaiN |  |  
                                    | khtanIn (Som, Ni, Yak)
 
 
                                    17689 Posts | 
                                        
                                          |  Posted - 2009-06-09 : 02:05:45 
 |  
                                          | [code]Insert into EmployeeMessageTable (EmployeeId,fk_MessageId) select  EmployeeId, @MessageIdfrom    EmployeeTablewhere   FK_DepartmentId = @DepartmentId[/code] KH[spoiler]Time is always against us[/spoiler]
 |  
                                          |  |  |  
                                    | amodiYak Posting Veteran
 
 
                                    83 Posts | 
                                        
                                          |  Posted - 2009-06-09 : 02:29:41 
 |  
                                          | Thanks KH. |  
                                          |  |  |  
                                |  |  |  |  |  |