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 |
|
amodi
Yak Posting Veteran
83 Posts |
Posted - 2009-06-08 : 12:46:15
|
| 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 example would be helpful.Thanks. |
|
|
raky
Aged Yak Warrior
767 Posts |
Posted - 2009-06-09 : 02:11:55
|
| Is this is what you want ??Declare @departmentID INT, @MessageID INTSELECT @departmentID = 1, @MessageID = 35Insert into EmployeeMessageTable(EmployeeId,fk_MessageId)SELECT DISTINCTEmployeeID,@MessageIDFROM EmployeeTable WHERE DepartmentId = @departmentID |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
|
|
amodi
Yak Posting Veteran
83 Posts |
Posted - 2009-06-09 : 02:33:42
|
| Thanks RakyKH. |
 |
|
|
amodi
Yak Posting Veteran
83 Posts |
|
|
raky
Aged Yak Warrior
767 Posts |
Posted - 2009-06-09 : 03:19:27
|
quote: Originally posted by amodi Thanks RakyKH.
Welcome... |
 |
|
|
|
|
|
|
|