Forum Discussion

JohnMathew's avatar
JohnMathew
Copper Contributor
Nov 25, 2024

one column refer to 2 columns

Hello there

global table is dbo.Employee(EmployeeId int, sex char(10))

Another global table is dbo.GradeEmployee(PolicyEmployeeId int (FK of Employee-EmployeeId), FaultEmployeeId int (FK of Employee-EmployeeId), grade char(5)

Another is my temp table called #TmpEmployee(EmployeeId int, employeeName char(50),  quantity)

GradeEmployee- PolicyEmployeeId is derived from Employee-EmployeeId

GradeEmployee- FaultEmployeeId is also derived from Employee-EmployeeId

                                                                                 

Now, the task is I want to get the data from #TmpEmployee table, there I want to Display in the below format PolicyEmployeeId, FaultEmployeeId, employeeNameSum(quantity)

Sum(quantity) is total quantity of a pair FaultEmployeeId, PolicyEmployeeId, note in #TmpEmployee table sometime the Quantity of FaultEmployeeId wont present; sometime the Quantity of PolicyEmployeeId wont present but, in the result it has to display.

How to write the select query?

Resources