我现在有一个数据库,前面有一个用户名(delphi 5)连接到。 我们使用以下方法调用报告:
with tcrpe.create(self) do
try
report_name := 'CrystalLotRecapSummary.rpt';
if fileexists(dmposting.tws_drive+'\tws\special\'+report_name) then
ReportName := dmposting.tws_drive+'\tws\special\'+Report_Name
else
ReportName := dmposting.tws_drive+'\tws\reports\harvest\'+Report_Name;
WindowButtonBar.PrintSetupBtn := true;
Paramfields.retrieve;
ParamFields[0].Value := cmbCropYear.text; // IN OLD REPORT
ParamFields[1].Value := 'ALL';
ParamFields[2].Value := real_to_str(unitfactor,0); // IN OLD REPORT
ParamFields[3].Value := cmbUnit.text; // IN OLD REPORT
ConnectMethod := useConnect;
Connect.Retrieve;
Connect.Password := 'PASSWORD';
Output := toWindow;
Execute;
finally
CloseJob;
end;
end; // PRINT SUMMARY BY WAREHOUSE
这很好用。问题是我们现在要有2个模式(sysdba和sysdba2)。
现在水晶报告查询看起来像:
SELECT
LOT_RECAP."GROWING_YEAR", LOT_RECAP."GREEN", LOT_RECAP."ADJUSTED", LOT_RECAP."SHIPPED",
LOT_RECAP."WAREHOUSE_ID", LOT_RECAP."REMAINING", LOT_RECAP."LOT_ID",
LOT_RECAP."FINISH_DRYING", LOT_RECAP."NAME", LOT_RECAP."STATUS",
LOT_RECAP."COMMODITY_ID",
LOT_RECAP."VARIETY_ID", LOT_RECAP."PRODUCER_ID", LOT_RECAP."LR_AVMOISTURE",
LOT_RECAP."PROJECTED", LOT_RECAP."NOTE", LOT_RECAP."MASTER_ID",
LOT_RECAP."VARIETY_TYPE",
LOT_RECAP."CROP", LOT_RECAP."STORAGE_ONLY"
FROM
"SYSDBA"."LOT_RECAP" LOT_RECAP
WHERE
LOT_RECAP."GROWING_YEAR" = 2009 AND
LOT_RECAP."COMMODITY_ID" = 'RICE' AND
LOT_RECAP."STORAGE_ONLY" = 'FALSE'
ORDER BY
LOT_RECAP."LOT_ID" ASC
我需要弄清楚某种方法让报告判断用户标识是否为sysdba,然后表是sysdba.lot_recap,如果用户标识为sysdba2,则表名为sysdba2.lot_recap。顺便说一句,我必须为大约300份报告做这件事。任何帮助将不胜感激。如果我没有提供足够的信息,请告诉我
答案 0 :(得分:1)
好的问题终于弄清楚了。进入报告本身然后转到设置位置。如果我从该位置删除架构名称Crystal Reports将允许我根据我登录的用户名动态分配架构名称。
答案 1 :(得分:0)
答案 2 :(得分:0)
创建一个联合两个表的视图,并通过新列“userid”选择:
create view LOT_RECAP_ALL as
select 'sysdba' userid, l.* from sysdba.lot_recap l
union all
select 'sysdba2' userid, l.* from sysdba2.lot_recap l
;
现在修改你的选择以从LOT_RECAP_ALL中选择并添加LOT_RECAP。“USERID”='sysdba'(或sysdba2):
SELECT
LOT_RECAP."GROWING_YEAR", LOT_RECAP."GREEN", LOT_RECAP."ADJUSTED", LOT_RECAP."SHIPPED",
LOT_RECAP."WAREHOUSE_ID", LOT_RECAP."REMAINING", LOT_RECAP."LOT_ID",
LOT_RECAP."FINISH_DRYING", LOT_RECAP."NAME", LOT_RECAP."STATUS",
LOT_RECAP."COMMODITY_ID",
LOT_RECAP."VARIETY_ID", LOT_RECAP."PRODUCER_ID", LOT_RECAP."LR_AVMOISTURE",
LOT_RECAP."PROJECTED", LOT_RECAP."NOTE", LOT_RECAP."MASTER_ID",
LOT_RECAP."VARIETY_TYPE",
LOT_RECAP."CROP", LOT_RECAP."STORAGE_ONLY"
FROM
"LOT_RECAP_ALL" LOT_RECAP
WHERE
LOT_RECAP."GROWING_YEAR" = 2009 AND
LOT_RECAP."COMMODITY_ID" = 'RICE' AND
LOT_RECAP."STORAGE_ONLY" = 'FALSE' AND
LOT_RECAP."USERID" = 'sysdba' -- or sysdba2
ORDER BY
LOT_RECAP."LOT_ID" ASC
根据您的连接用户,您可能需要添加
grant select on LOT_RECAP_ALL to sysdba;
或
grant select on LOT_RECAP_ALL to sysdba2;
也许您还需要在sysdba(2).lot_recap上向视图所有者添加选择授权。从这里说不出来,取决于你的架构的访问权限。