0

我有一个这样的存储过程

SELECT t.transactID, 
       t.TBarcode, 
       t.PAICID, 
       t.Status, 
       k.HBarcode, 
       ISNULL(COALESCE(u.uname, e.Ename), 'Deliver') AS EName 
FROM   
    Transaction_tbl 
LEFT JOIN 
    UserMaster_tbl u ON u.ECode = t.Ecode AND t.Status = 0 
LEFT JOIN 
    EmployeeMaster_tbl e ON e.ECode = t.ECode AND t.Status = 1 OR e.Ecode = t.DelEcode AND t.Status = 4 
LEFT JOIN 
    KHanger_tbl k ON t.transactID = k.transactid AND t.Status = 2 
WHERE  
    t.TBarcode = @Carid

我有这样的交易表

transactID  TBarcode   Ecode    DelEcode     PAICID  status
1            1234       E001        E002         1         0
2             4567      E002        E001         2         1
3            24567      E003        E003         2         4

我有用户主表

uid   Ecode uname
1      E001  jas
2      E002  ramu

我有 Employeemaster 表

Ecode   Ename
E001    jaseem
E002    ramesh

Uid 和 PAICID 相同

如果 status =0 则取对应 PAICID 的 uid ,然后取对应 uid 的 Ecode ,然后显示 Employee 主表中的 Ename ,我该如何编写这个存储过程?

4

1 回答 1

0
SELECT Ename
FROM transaction
INNER JOIN master ON master.Ecode = transaction.Ecode
INNER JOIN Employeemaster ON Employeemaster.Ecode = master.Ecode
WHERE transaction.status = 0
于 2013-06-21T19:51:51.370 回答