-1

![Cognost 报告工作室查询资源管理器]

下面是一张表的快照。

**Acctno     ClientNo     ClientName     PrimaryOffId         SecondaryOffID**
  101      11111        ABC corp           3                        Not Defined
  102      11116        XYZ Inc            5                        Not Defined
  103      11113        PQRS Corp          2                        9
  104      55555        Food LLC           4                        11
  105      99999        Kwlg Co            1                        Not Defined
  106      99999        Kwlg Co            1                        Not Defined
  107      11112        LMN Corp           Not Defined              6
  108      11112        LMN Corp           Not Defined              6
  109      11115        Sleep Co           4                        10
  110      44444        Cool Co            Not Defined              8
  111      11114        Sail LLC           3                        Not Defined
  112      66666        Fun Inc            1                        Not Defined
  113      88888        Job LLC            5                        12
  114      22222        Acc Co             Not Defined              Not Defined
  115      77777        Good Corp          2                        Not Defined
  116      33333        City  LLC          Not Defined              7
  117      33333        City  LLC          Not Defined              7
  118      33333        City  LLC          Not Defined              7
  119      11111        ABC corp           3                        Not Defined

我想用来自该表的名称替换 PrimaryOffID 和 SecondaryOffID

EmpID     Names
  1      Cathy
  2      Chris
  3      John
  4      Kevin
  5      Mark
  6      Celine
  7      Jane
  8      Phil
  9      Jess
 10      Jose
 11      Nick
 12      Rosy

结果应如下所示: 请注意,如果 Cathy 是 PrimaryOfficer,她就不能是 SecondaryOfficer,反之亦然。此逻辑适用于所有名称

Acctno  ClientNo    Client Name PrimOffName SecondaryOffName
 101    11111   ABC corp          John           Not Defined
 102    11116   XYZ Inc           Mark           Not Defined
 103    11113   PQRS Corp         Chris          Jess
 104    55555   Food LLC          Kevin          Nick
 105    99999   Kwlg Co           Cathy          Not Defined
 106    99999   Kwlg Co           Cathy          Not Defined
 107    11112   LMN Corp          Not Defined        Celine
 108    11112   LMN Corp          Not Defined        Celine
 109    11115   Sleep Co          Kevin          Jose
 110    44444   Cool Co           Not Defined    Phil
 111    11114   Sail LLC          John           Not Defined
 112    66666   Fun Inc           Cathy          Not Defined
 113    88888   Job LLC           Mark           Rosy
 114    22222   Acc Co            Not Defined   Not Defined
 115    77777   Good Corp         Chris          Not Defined
 116    33333   City  LLC         Not Defined   Jane
 117    33333   City  LLC         Not Defined   Jane
 118    33333   City  LLC         Not Defined   Jane
 119    11111   ABC corp          John           Not Defined

但相反,它看起来像这样:

Acctno  ClientNo    ClientName  PrimOffName SecondaryOffName
   101  11111   ABC corp         John             Not Defined
   102  11116   XYZ Inc          Mark             Not Defined
   103  11113   PQRS Corp        Chris            Not Defined
   103  11113   PQRS Corp        Not Defined           Jess
   104  55555   Food LLC         Kevin            Not Defined
   104  55555   Food LLC         Not Defined     Nick
   105  99999   Kwlg Co          Cathy            Not Defined
   106  99999   Kwlg Co          Cathy            Not Defined
   107  11112   LMN Corp         Not Defined         Celine
   108  11112   LMN Corp         Not Defined         Celine
   109  11115   Sleep Co         Kevin            Not Defined
   109  11115   Sleep Co         Not Defined              Jose
   110  44444   Cool Co          Not Defined              Phil
   111  11114   Sail LLC         John             Not Defined
   112  66666   Fun Inc          Cathy            Not Defined
   113  88888   Job LLC          Mark             Not Defined
   113  88888   Job LLC          Not Defined              Rosy
   114  22222   Acc Co           Not Defined              Not Defined
   115  77777   Good Corp        Chris            Not Defined
   116  33333   City  LLC        Not Defined    jane
   117  33333   City  LLC        Not Defined    jane
   118  33333   City  LLC        Not Defined    jane
   119  11111   ABC corp         John            Not Defined

请注意,现在 Acctno 不再是唯一的,如果名称应该在两个字段中一起出现,它会分开并在下一行中提供输出,创建多个记录。我尝试了各种选择,但没有奏效。请注意,我正在 Cognos Studio 中创建此报告。请提出可能的查询以获得所需的结果。提前致谢。感谢你的帮助。

4

1 回答 1

1

您没有说明您使用的是哪个版本的 Cognos。“Cognos Studio”是模棱两可的。我最熟悉 8.4.1,但即便如此,您也不会说您是否尝试在 Cognos 模型、Query Studio、Event Studio 或 Report Studio 中定义它。

其次,在 StackOverflow 上提问时,您应该始终展示您到目前为止所获得的信息。人们希望看到您所做的工作以表明您想要修复,而不是重复大部分工作。这就是你投反对票的原因。

就普通 SQL 而言,您需要这样做:

SELECT a.Acctno, a.ClientNo, a.ClientName, coalesce(e1.Names,'Not Defined') "PrimaryOffName", coalesce(e2.Names,'Not Defined') "SecondaryOffName"
FROM Account a
LEFT OUTER JOIN Emp e1
    ON t.PrimaryOffID = e1.EmpID
LEFT OUTER JOIN Emp e2
    ON t.PrimaryOffID = e2.EmpID

我编了表名。您可以在 Report Studio 中执行此操作,方法是为查询创建两个查询Emp并将它们外部连接到Account查询之后。

如果可以,您需要将OffID字段移动到单独的联结表中并将它们从Account表中删除。然后,您可以在该联结表中创建标识主要和次要的状态字段或标志。

于 2014-05-02T16:54:47.743 回答