是否可以查看Cognos查詢中使用的SQL?如何從Cognos獲取查詢定義?
例如爲了得到一個報告的XML定義,您可以使用下面的SQL(從https://stackoverflow.com/a/24335760/361842複製):
SELECT CMOBJNAMES.NAME AS ObjName
, CMOBJECTS.PCMID
, CMCLASSES.NAME AS ClassName
, cast(CMOBJPROPS7.spec as xml) ReportDefinition
FROM CMOBJECTS
INNER JOIN CMOBJNAMES ON CMOBJECTS.CMID = CMOBJNAMES.CMID
INNER JOIN CMCLASSES ON CMOBJECTS.CLASSID = CMCLASSES.CLASSID
LEFT OUTER JOIN CMOBJPROPS7 ON CMOBJECTS.CMID = CMOBJPROPS7.CMID
WHERE CMOBJECTS.CLASSID IN (10, 37)
ORDER BY CMOBJECTS.PCMID;
...並從XML,你可以經常發現sqltext
元素賦予底層的SQL。但是,在使用現有查詢的情況下,很難看到數據來自哪裏。
我想要相當於上面的SQL查找查詢定義;儘管迄今爲止一直未能找到任何這樣的專欄。
失敗的是,有沒有辦法通過UI找到這個定義?我查看了Query Studio,發現查詢的lineage
,它提供了有關查詢列的一些信息,但並未明確數據的來源。
注:通過查詢我指的是那些如R5BZDDAN_GRAPH
在下面的截圖來自Query Studio中:
...這將在Cognos報告的方式,例如被稱爲如:
<query name="Q_DEMO">
<source>
<model/>
</source>
<selection autoSummary="false">
<dataItem aggregate="none" name="REG_REG" rollupAggregate="none">
<expression>[AdvRepData].[Q_R5BZDDAN_GRAPH].[REG_REG]</expression>
</dataItem>
<dataItem aggregate="none" name="REG_ORG" rollupAggregate="none">
<expression>[AdvRepData].[Q_R5BZDDAN_GRAPH].[REG_ORG]</expression>
</dataItem>
<!-- ... -->
UPDATE
爲他人謀取利益,這裏是上述代碼的修改版本拉回報告。定義:
;with recurse
as (
select Objects.CMID Id, ObjectClasses.Name Class, ObjectNames.NAME Name
, cast('CognosObjects' as nvarchar(max)) ObjectPath
from CMOBJECTS Objects
inner join CMOBJNAMES ObjectNames
on ObjectNames.CMID = Objects.CMID
and ObjectNames.IsDefault = 1 --only get 1 result per object (could filter on language=English (LocaleId=24/select LocaleId from CMLOCALES where Locale = 'en'))
inner join CMCLASSES ObjectClasses on ObjectClasses.CLASSID = Objects.CLASSID
where Objects.PCMID = objects.CMID --cleaner than selecting on root since not language sensitive
--where ObjectClasses.NAME = 'root'
union all
select Objects.CMID Id, ObjectClasses.Name Class, ObjectNames.NAME Name
, r.ObjectPath + '\' + ObjectNames.NAME ObjectPath --I use a backslash rather than forward slash as using this to build a windows path
from recurse r
inner join CMOBJECTS Objects
on objects.PCMID = r.Id
and Objects.PCMID != objects.CMID --prevent ouroboros
inner join CMOBJNAMES ObjectNames
on ObjectNames.CMID = Objects.CMID
and ObjectNames.IsDefault = 1 --only get 1 result per object (could filter on language=English (LocaleId=24/select LocaleId from CMLOCALES where Locale = 'en'))
inner join CMCLASSES ObjectClasses
on ObjectClasses.CLASSID = Objects.CLASSID
)
select *
from recurse
where Class in ('report','query')
order by ObjectPath
所有報表的查詢定義是在報告中XML的方式改變了,如果這就是你意思。 「查詢定義」和「現有查詢」究竟是什麼意思?你是指報告中的查詢快捷鍵,報告中的SQL源?如果它在報告中,那麼它在XML中。棘手的部分是當報告是從包中的查詢主題製作的 - 需要使用報告定義對包進行評估並且不存儲在任何地方 –
謝謝@NickMcDermaid。我現在添加了一個截圖來幫助澄清我的問題。我熟悉用直接在報表中嵌入sql語句;但在這種情況下,我希望瞭解預定義的查詢;我認爲這就是你所說的「查詢主題」;儘管Cognos不太熟悉Cognos術語。再次感謝。 –
JohnLBevan