Source table for view QRYSTAT in Netezza - sql

I'm currently working in a Netezza environment on Aginity Workbench and I was planning on using some of the columns from the Management View _V_QRYSTAT to populate a graph in MicroStrategy.
Unfortunately, I cannot get MicroStrategy to recognize any of the columns in _V_QRYSTAT. I don't think that it can read columns from views, and I figured that the best way around this would be to find out which table the _V_QRYSTAT view is getting its data from, but I can't figure out a way to find the source table of a view in Netezza. Does anyone know a method that can be used in Netezza on Aginity Workbench for locating the source table of a view (specifically _V_QRYSTAT)?
I'm very new to SQL, Netezza and MicroStrategy, so I apologize if I am being unclear. Let me know if further elaboration is needed.

I'm pretty sure that MicroStrategy will recognize and work with views, but to answer your question directly, you can see the view definition by querying the _V_VIEW system view.
select definition from _v_view where viewname = '_V_QRYSTAT';
DEFINITION
---------
SELECT
QS.QS_SESSIONID,
QS.QS_PLANID ,
QS.QS_CLIENTID ,
CASE
WHEN ((VU.OBJID NOTNULL
)
OR ("CURRENT_USEROID"() = 4900
)
)
THEN QS.QS_CLIIPADDR
ELSE "NAME"(NULL::"VARCHAR")
END AS QS_CLIIPADDR,
CASE
WHEN ((VU.OBJID NOTNULL
)
OR ("CURRENT_USEROID"() = 4900
)
)
THEN QS.QS_SQL
ELSE TEXT(NULL::"VARCHAR")
END AS QS_SQL ,
QS.QS_STATE ,
QS.QS_TSUBMIT ,
QS.QS_TSTART ,
QS.QS_PRIORITY,
QS.QS_PRITXT ,
QS.QS_ESTCOST ,
QS.QS_ESTDISK ,
QS.QS_ESTMEM ,
QS.QS_SNIPPETS,
QS.QS_CURSNIPT,
QS.QS_RESROWS ,
QS.QS_RESBYTES
FROM
((DEFINITION_SCHEMA."_T_QRYSTAT" QS
LEFT JOIN DEFINITION_SCHEMA."_T_SESSCTX" SS ON (
(QS.QS_SESSIONID = SS.SESSION_ID
)
))
LEFT JOIN DEFINITION_SCHEMA."_V_USER" VU ON (
(SS.SESSION_USERNAME = VU.USERNAME
)
));
(1 row)
This will almost certainly take you a couple of recursions down, as the view you are interested in is based on either views as well as tables.

Related

Query to identify who can make changes to SQL DB objects

I am looking for a query to run on SQL server to identify who can change DB objects structure (DLL) within a SQL server. Please help. Thank you.
You can look in the Default Trace:
SELECT TE.name AS EventName ,
T.DatabaseName ,
t.ObjectName,
t.NTDomainName ,
t.ApplicationName ,
t.LoginName ,
t.StartTime
FROM sys.traces tr
cross apply sys.fn_trace_gettable(CONVERT(VARCHAR(150),
( SELECT f.[value] FROM sys.fn_trace_getinfo(tr.id) f WHERE f.property = 2 )), DEFAULT) T
JOIN sys.trace_events TE ON T.EventClass = TE.trace_event_id
WHERE
tr.is_default = 1
and name like 'Object:%'
ORDER BY t.StartTime ;
Thanks for efforts. I found the following site which gives you multiple queries determining effective database engine permissions.
https://learn.microsoft.com/en-us/sql/relational-databases/security/authentication-access/determining-effective-database-engine-permissions?view=sql-server-2017

How to get a query definition from Cognos?

Is it possible to view the SQL used in Cognos's queries?
e.g. To get the XML definition of a report you can use the below SQL (copied from 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;
... and from that XML you can often find sqltext elements giving the underlying SQL. However, where existing queries are being used it's hard to see where that data's coming from.
I'd like the equivalent of the above SQL to find Query definitions; though so far have been unable to find any such column.
Failing that, is there a way to find this definition through the UI? I looked under Query Studio and found the query's lineage which gives some information about the query columns, but doesn't make the data's source clear.
NB: By query I'm referring to those such as R5BZDDAN_GRAPH in the below screenshot from Query Studio:
... which would be referred to in a Cognos report in a way such as:
<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
For the benefit of others, here's an amended version of the above code for pulling back report definitons:
;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
Terminology:
Query Subject can be considered a table
Query Item can be considered a column
For your example the SQL might be defined in the R5BZDDAN_GRAPH query subject which is in turn defined in the Framework Manager model. The framework manager model is defined in a .cpf file which isn't in the content store at all. (it is an XML file though). This file is 'published' to Cognos to make packages.
There is also a cached version of the framework manager file on the actual cognos server (a .cqe file) although it is generally not recommended to rely on this
I say your SQL might be defined. If the query subject is a SQL query subject then that is where it is defined. If If the query subject is a model query subject then it is just a list of query items from other query subjects. These might be from many other query subjects which then have joins defined in Framework Manager. So there is no actual SQL defined there - it gets generated at run time
I'm not sure of your end requirement but there are three other ways to get SQL:
In Report Studio you can 'show generated SQL' on each query
In Framework Manager you can select one or more query subjects and show generated SQL
You can use a monitoring tool on your database to see what SQL is being submitted
If you just want to know how numbers are generated in your report, the most direct solution is to monitor your database.
Lastly keep in mind that in some rare cases, SQL defined in Framework Manager might be altered by the way the report is written

sql query is too complex

Please help me to simplify this complex query statement because when I run the code it will always end up with "Query is too complex" error
SELECT tblTimeReport.DBIDTimeReport, tblTimeReport.DBIDHumanResource
, tblHumanResource.FullName, tblHumanResource.Title, tblTimeReport.DBIDProject
, tblProject.ProjectID, tblProject.ProjectName, tblTimeReport.DBIDActivity
, tblActivity.ActivityID, tblActivity.ActivityName, tblTimeReport.DateTR AS TRDate
, tblTimeReport.StartTime, tblTimeReport.Duration, tblTimeReport.HourlyRate
, Sum([Duration]*[HourlyRate]) AS Cost, tblTimeReport.Comments, tblTimeReport.Deleted
, tblTimeReport.InputBy, tblHumanResourceInput.[FullName] AS InputByFullName
, tblTimeReport.InputDate
FROM (((tblTimeReport
LEFT JOIN tblHumanResource
ON tblTimeReport.DBIDHumanResource = tblHumanResource.DBIDHumanResource)
LEFT JOIN tblHumanResource AS tblHumanResourceInput
ON tblTimeReport.InputBy = tblHumanResourceInput.DBIDHumanResource)
LEFT JOIN tblProject
ON tblTimeReport.DBIDProject = tblProject.DBIDProject)
LEFT JOIN tblActivity ON tblTimeReport.DBIDActivity = tblActivity.DBIDActivity
%WhereCondition%
GROUP BY tblTimeReport.DBIDTimeReport, tblTimeReport.DBIDHumanResource
, tblHumanResource.FullName, tblHumanResource.Title, tblTimeReport.DBIDProject
, tblProject.ProjectID, tblProject.ProjectName, tblTimeReport.DBIDActivity
, tblActivity.ActivityID, tblActivity.ActivityName, tblTimeReport.DateTR
, tblTimeReport.StartTime, tblTimeReport.Duration, tblTimeReport.HourlyRate
, tblTimeReport.Comments, tblTimeReport.Deleted, tblTimeReport.InputBy
, tblHumanResourceInput.FullName, tblTimeReport.InputDate
Thanks in advance
If this is for a report, as the names of your columns imply, you my be experiencing this:
Reports create temporary queries for each section of the report,
including the report header, page header, group header, detail
section, group footer, page footer, and report footer. All of the
temporary queries for each report are combined into a segmented
virtual table (SVT). The final output must be compiled within the 64K
segment limit.
http://support.microsoft.com/kb/103429
So even if your query is compiled within the limits, its size is multiplied by number of sections. The article implies newer versions of Access have increased dynamic limit, which might help.
You could try creating a view for the group by aggregation, and leave out all of the name columns, and only include the critical IDs. Then use a join against the view to pull in names. I'm not sure though if this would help because I don't know if the contents of the view get pulled in whenever Access compiles the query.

Sugar crm suctom field sql select error

I've added few additional fields to Accounts module. Also added same fields to detailed search. One field is decimal, another text, filled from drop down menu. After running a test search everything looked fine. But not long time ago I needed to see all the items in the search. Search was made using my new added fields as parameters. As you may already know, search in sugar crm shows only first 20 items. So, after trying to access another 20 items i've got an empty list.
sugarcrm.log showed me sql query error:
11/12/12 00:09:33 [6300][ca4960aa-6cce-065a-be1d-4fa7b40db052][FATAL] Query Failed:SELECT TOP 21 * FROM
(SELECT ROW_NUMBER()
OVER (ORDER BY accounts.name) AS row_number,
accounts.id ,
**accounts_cstm.print_srv_prov_c**,
accounts.name ,
accounts.billing_address_city ,
accounts.billing_address_country ,
accounts.phone_office ,
LTRIM(RTRIM(ISNULL(jt0.first_name,'')+N' '+ISNULL(jt0.last_name,''))) assigned_user_name ,
jt0.created_by assigned_user_name_owner ,
N'Users' assigned_user_name_mod,
accounts.annual_revenue ,
accounts.account_type ,
**accounts_cstm.print_srv_prov_c** ,
accounts.assigned_user_id
FROM accounts
LEFT JOIN accounts_cstm ON accounts.id = accounts_cstm.id_c
LEFT JOIN users jt0 ON accounts.assigned_user_id=jt0.id AND jt0.deleted=0 AND jt0.deleted=0
where ((accounts.account_type in (N'potencial_client') ) AND ( accounts_cstm.print_srv_prov_c in (N'itel'))) AND accounts.deleted=0
) AS a
WHERE row_number > 20::: [Microsoft][SQL Server Native Client 10.0][SQL Server]The column 'print_srv_prov_c' was specified multiple times for 'a'.
All fields were added using Studio tool, and source code has been intact.
sql error is happening, because column accounts_cstm.print_srv_prov_c is used two times. Why this is happening and how to fix it.
I am Using SugarCRM CE 6.4.4

new to oracle, need to join tables to get the field values in my resultset

i know sql server and not oracle, so i will speak in sql server language to describe what i need from oracle.
i have a oracle query i am developing that needs to select the following fields detailed below. i found all but two of them in the BUG table. the other two are in other tables that i am not clear on how to get into my oracle SQL.
also i want to convert the field names defined in Oracle to field names that are more meaningful to me and indecently the dame as the field names in my sql table. (this is part of an oracle extract/ sql2005 insert job) this may need to be oricalafied as well cause im writing it the sql way and just expecting it to work... let me know.
my sql so far- i added '' as placeholders for the 2 fields i need to join to:
BG_SUBJECT field is part of the ALL_LISTS Table, where AL_ITEM_ID is the primary key.
DetectedInRelease is the REL_NAME field in the RELEASES table where REL_ID is the primary key.
SELECT
bg_user_56 AS Project,
bg_user_60 AS SubSystem,
BG_USER_81 AS AssignedToUserName,
bg_responsible AS AssignedTo,
bg_status AS Status,
BG_USER_15 AS BusinessFunction,
bg_detection_date AS DetectedOnDate,
BG_SEVERITY AS BusinessSeverity,
bg_user_36 AS TestingSeverity,
bg_bug_id AS DefectID,
Bg_User_09 AS EstFixedDate,
bg_user_25 AS EstReadyForRetest,
BG_DESCIPTION AS description,
BG_USER_03 AS DetectedInDeploymentEvent,
'' AS DetectedInRelease,--- ??? not in bug table !!!!
BG_USER_47 AS FunctionalAreaWorkstream,
BG_USER_19 AS PlannedFixInDeploymentEvent,
BG_USER_55 AS PlannedFixInRelease,
BG_USER_57 AS PTMTestManager,
Bg_User_58 AS RemediatingCTOName,
'' AS Subject,--- ??? not in bug table !!!
bg_summary AS Summary,
bg_user_80 AS MLTestEnvironment,
GETDATE() AS LoadDateTime,
bg_user_12 AS Deferred
FROM tascs_ml_bac_transition_db.BUG
the query syntax is effectively the same, GETDate will need to be SYSDATE however, included as a sample inner join
SELECT
BUG.bg_user_56 AS Project ,
BUG.bg_user_60 AS SubSystem ,
BUG.BG_USER_81 AS AssignedToUserName ,
BUG.bg_responsible AS AssignedTo ,
BUG.bg_status AS Status ,
BUG.BG_USER_15 AS BusinessFunction ,
BUG.bg_detection_date AS DetectedOnDate ,
BUG.BG_SEVERITY AS BusinessSeverity ,
BUG.bg_user_36 AS TestingSeverity ,
BUG.bg_bug_id AS DefectID ,
BUG.Bg_User_09 AS EstFixedDate ,
BUG.bg_user_25 AS EstReadyForRetest ,
BUG.BG_DESCIPTION AS description ,
BUG.BG_USER_03 AS DetectedInDeploymentEvent ,
REL.REL_NAME AS DetectedInRelease , --- ??? not in bug table !!!!
BUG.BG_USER_47 AS FunctionalAreaWorkstream ,
BUG.BG_USER_19 AS PlannedFixInDeploymentEvent,
BUG.BG_USER_55 AS PlannedFixInRelease ,
BUG.BG_USER_57 AS PTMTestManager ,
BUG.Bg_User_58 AS RemediatingCTOName ,
al.BG_SUBJECT AS Subject , --- ??? not in bug table !!!
BUG.bg_summary AS Summary ,
BUG.bg_user_80 AS MLTestEnvironment ,
sysdate AS LoadDateTime , --changed to sysdate
BUG.bg_user_12 AS Deferred
FROM
tascs_ml_bac_transition_db.BUG BUG
INNER JOIN
ALL_LISTS al
ON BUG.AL_ITEM_ID = al.AL_ITEM_ID --THIS ASSUMES AL_ITEM_ID IS COMMON FIELD
INNER JOIN
RELEASES REL
ON BUG.REL_ID = REL.REL_ID --THIS ASSUMES REL_ID IS COMMON FIELD
I'm going to take a stab at this:
SELECT
bg_user_56 AS Project,
bg_user_60 AS SubSystem,
BG_USER_81 AS AssignedToUserName,
bg_responsible AS AssignedTo,
bg_status AS Status,
BG_USER_15 AS BusinessFunction,
bg_detection_date AS DetectedOnDate,
BG_SEVERITY AS BusinessSeverity,
bg_user_36 AS TestingSeverity,
bg_bug_id AS DefectID,
Bg_User_09 AS EstFixedDate,
bg_user_25 AS EstReadyForRetest,
BG_DESCIPTION AS description,
BG_USER_03 AS DetectedInDeploymentEvent,
rel.BG_DetectedInRelease AS DetectedInRelease,--- ??? not in bug table !!!!
BG_USER_47 AS FunctionalAreaWorkstream,
BG_USER_19 AS PlannedFixInDeploymentEvent,
BG_USER_55 AS PlannedFixInRelease,
BG_USER_57 AS PTMTestManager,
Bg_User_58 AS RemediatingCTOName,
al.BG_SUBJECT AS Subject,--- ??? not in bug table !!!
bg_summary AS Summary,
bg_user_80 AS MLTestEnvironment,
GETDATE() AS LoadDateTime,
bg_user_12 AS Deferred
FROM tascs_ml_bac_transition_db.BUG B, ALL_LISTS al, releases rel
WHERE al.al_item_id = b.al_item_id and rel.rel_id = b.rel_id;
It's hard to guess if this will work since I don't have a complete DDL of these tables, but this is my best guess based on what you've given. I assumed that BUG had fields with the same names as the ones you need to join on. This might not be valid, feel free to clarify.
You could also use INNER JOIN ON syntax if you prefer it.