0

我有这样的存储过程

Select k.HBarcode, m.make,t.plateno ,v.vtype ,l.locname,mdl.model,c.Colname 
from   transaction_tbl t,
       KHanger_tbl k,
       make_tbl m,
       vtype_tbl v,
       Location_tbl l,
       Model_tbl mdl,
       Color_tbl C  
 where t.tbarcode=@carid and 
       t.mkid=m.mkid and 
       v.vtid=t.vtid and 
       t.locid=l.locid and 
       mdl.mdlid=t.mdlid and 
       t.colid=c.colid and 
       t.transactID=k.transactID

在执行此操作时得到输出

HBarcode     make     plateno    vtype   locname          model        Colname
34           BMW      44554      Normal  Fashion Avenue   520          Red

我还有两个表,从事务表中我可以得到 transactid (例如:t.transactID),然后我可以 从“KHanger_tbl”中获取相应的tid ,然后我想从“终端”表中显示对应tid的唯一名称

1-KHanger_tbl

transactid                              HBarcode                tid
--------------------------------------- ----------------------------------
19                                      34                      7
22                                      002                     5
21                                      1                       7
23                                      200005                   6

2- Terminals_tbl

tid         UniqueName
----------- --------------------------------------------------
5           Key Room-1
6           Podium -1
7           Key Room - 2

预期产出

 UniqueName HBarcode make plateno vtype  locname               model  Colname
 -------------------------------------------------------------------------------
 KeyRoom-2  34       BMW  44554   Norma Fashion Avenue       520      Red

那么我该如何为此编写存储过程,如果有人知道,请帮助我

4

1 回答 1

0

像这样的东西可能吗?

Select  term.UniqueName , 
   k.HBarcode, m.make,t.plateno ,v.vtype ,l.locname,mdl.model,c.Colname 
from transaction_tbl t,
     KHanger_tbl k,
     make_tbl m,
     vtype_tbl v,
     Location_tbl l,
     Model_tbl mdl,
     Color_tbl C  
     ,
     Terminals_tbl Term

where t.tbarcode=@carid and 
      t.mkid=m.mkid and 
      v.vtid=t.vtid and 
      t.locid=l.locid and 
      mdl.mdlid=t.mdlid and 
      t.colid=c.colid and 
      t.transactID=k.transactID 
      and
      term.tid = t.transactID
于 2013-06-19T20:35:08.997 回答