2009-03-03 160 views
0

我有一個名爲tblIssueTicket表 tblIssueTicket包含字段:TicketID,TicketRequesterID,ApprovalManagerID,RequestDate,ApprovalDate,TicketStatusSQL查詢聯接

有一個叫tblEmployeeProfile另一個表。 tblEmployeeProfile包含字段僱員,EmployeeFirstName,EmployeeLastName

我需要顯示以下記錄:

TicketID,TicketRequesterFullName,ApprovalManagerFullName,RequestDate,ApprovalDate,TicketStatus

我有搞清楚的問題查詢返回TicketRequester &全名ApprovalManager字段的全名。

我的查詢到目前爲止是這樣的:

Select it.TicketID, 
    ep.Firstname + ' ' + ep.EmployeeLastName AS TicketRequestorFullName, 
    it.RequestDate, it.ApprovalDate, it.TicketStatus 
FROM tblIssueTicket it, tblEmployeeProfile ep 
WHERE ep.EmployeeID = it.TicketRequesterID 

任何意見將不勝感激。

感謝

CM

回答

5
SELECT 
    it.TicketID,  
    ep.Firstname + ' ' + ep.EmployeeLastName AS TicketRequestorFullName,  
    mp.Firstname + ' ' + mp.EmployeeLastName AS ApprovalManagerFullName,  
    it.RequestDate, 
    it.ApprovalDate, 
    it.TicketStatus 
FROM  
    tblIssueTicket it 
    INNER JOIN tblEmployeeProfile ep ON ep.EmployeeID = it.TicketRequesterID 
    INNER JOIN tblEmployeeProfile mp ON mp.EmployeeID = it.ApprovalManagerID