T-SQL - 将数据插入父表和子表笔记:表变量由实时环境中的实际表替换。EmployeeID和ParentEmployeeDepartmentID列的值并不总是相互匹配。实时环境在udt(tEmployeeData)中的记录多于4目标:udt(tEmployeeData)将被传递给过程该过程应首先将数据插入@MainEmployee表中(并获取EmployeeIDs)接下来,该过程应该将数据插入@ParentEmployeeDepartment表中(并获取ParentEmployeeDepartmentID) - 注意EmployeeID来自上一个输出。然后,该过程应该基于DepartmentType(“A”=插入@ChildEmployeeDepartmentTypeA和“B”=插入@ChildEmployeeDepartmentTypeB)拆分子级数据。程序应该运行得快(需要逐行操作)输出:@MainEmployee:EmployeeID FirstName LastName---------------------------------1 Tom_FN Tom_LN2 Mike_FN Mike_LN3 Joe_FN Joe_LN4 Dave_FN Dave_LN@ParentEmployeeDepartment:EmployeeID ParentEmployeeDepartmentID DepartmentType-------------------------------------------------------1 1 A2 2 B3 3 A4 4 B@ChildEmployeeDepartmentTypeA:ParentEmployeeDepartmentID DepartmentBuilding DepartmentEmployeeLevel DepartmentTypeAMetadata---------------------------------------------------------------------------------------------------------1 101 IV Tech/IT3 101 IV Tech/IT@ChildEmployeeDepartmentTypeB:ParentEmployeeDepartmentID DepartmentBuilding DepartmentEmployeeLevel DepartmentTypeAMetadata----------------------------------------------------------------------------------------------------------2 OpenH XII Med4 OpenC XII Lab我知道我可以使用OUTPUT插入后条款,并得到EmployeeID和ParentEmployeeDepartmentID,但我不知道如何插入正确的子记录与正确映射到父表右表。任何帮助,将不胜感激。
1 回答
- 1 回答
- 0 关注
- 571 浏览
添加回答
举报
0/150
提交
取消