WHERE clause in MDX for Dynamic Management Views - sql-server

I am trying to query the metadata from a tabular cube using DMVs. I was able to get it to work without a where clause, but I can't seem to get a where clause to work. Any Advice?
Here is the code that works:
SELECT
[MEASURE_CAPTION] AS [Measure]
,[MEASURE_IS_VISIBLE] AS [Visable]
,[DESCRIPTION] AS [Description]
,[MEASURE_DISPLAY_FOLDER] AS [Display Folder]
,[EXPRESSION] AS [Calculation]
FROM $SYSTEM.MDSCHEMA_MEASURES
The WHERE clauses that I have tried are:
WHERE ([MEASURE_IS_VISIBLE].[members].[true])
I get the following error:
The dot expression is not allowed in the context at line 9, column 1.
Also:
WHERE [MEASURE_IS_VISIBLE] = TRUE
I get the following error:
Error: A Boolean expression is not allowed in the context at line 9, column 7.
I have tried many veriations on these themes, but always get the same result. I am not at all familiar with how MDX works, so any assistance would be appreciated.

MEASURE_IS_VISIBLE is a boolean column and must be filtered as such. The following query filters the results to only those with a MEASURE_IS_VISIBLE value of true. Change this to WHERE NOT MEASURE_IS_VISIBLE for rows where this is false. You can see the datatypes for this DMV from the documentation here.
SELECT
[MEASURE_CAPTION] AS [Measure]
,[MEASURE_IS_VISIBLE] AS [Visable]
,[DESCRIPTION] AS [Description]
,[MEASURE_DISPLAY_FOLDER] AS [Display Folder]
,[EXPRESSION] AS [Calculation]
FROM $SYSTEM.MDSCHEMA_MEASURES
WHERE MEASURE_IS_VISIBLE

Related

PyFlink - Issue with UNNEST: query uses an unsupported SQL feature?

I am trying to flatten an array using UNNEST function in the Table API.
Am I doing something wrong or it is not a supported function ? This page suggests it though: https://ci.apache.org/projects/flink/flink-docs-master/dev/table/sql/queries.html
Thanks !
Code
Python udf
#udf(input_types=DataTypes.STRING(), result_type=DataTypes.ARRAY(DataTypes.STRING()))
def explode(s):
return 3*[s]
t_env.register_function("explode", explode)
Processing
tab = t_env.from_path('mySource').select("id, explode(dummy) as dummy_list")
t_env.register_table("temp_table", tab)
t_env.sql_query("SELECT t.item as dummy_item FROM UNNEST(select dummy_list from temp_table) AS t(item)").insert_into("mySink")
Execution
t_env.execute("dummy_unnest")
Error
TableException: Cannot generate a valid execution plan for the given query:
LogicalProject(dummy_item=[$0])
Uncollect
LogicalProject(EXPR$0=[org$apache$flink$table$functions$python$PythonScalarFunction$908596b4671476ee325743dba92ed6c7($1)])
LogicalTableScan(table=[[default_catalog, default_database, mySource]])
This exception indicates that the query uses an unsupported SQL feature.
Please check the documentation for the set of currently supported SQL features.
I think you can change the query to
select id, dummy_item from temp_table CROSS JOIN UNNEST(dummy_list) AS t (dummy_item)

How to filter "show tables"

I would like to filter the output of show tables.
The documentation has one example on how to do this using result_scan(last_query_id()), but for me the example does not work:
show tables;
select "schema_name", "name" as "table_name", "rows"
from table(result_scan(last_query_id()))
where "rows" = 0;
-- SQL compilation error: error line 1 at position 8 invalid identifier 'SCHEMA_NAME'
The column SCHEMA_NAME is actually in the output of show tables,
so I do not understand what is wrong.
Best,
Davide
Run the following on your account and see what it is set to:
show parameters like 'QUOTED_IDENTIFIERS_IGNORE_CASE';
If this is set to TRUE, then it is ignoring the quotes in your query, which will then uppercase the column names, which won't match to the lowercase names of the SHOW output.
To resolve for your own session, you can run the following:
ALTER SESSION SET QUOTED_IDENTIFIERS_IGNORE_CASE = False;
You can also change this at a user or account level, if you wish. Setting this value to TRUE isn't recommended for the reason that you are running into.
You can reference the filter column using $<col_n> syntax (#8 for rows).
Example:
show tables;
select *
from table(result_scan())
where $8 > 5
That being said, your query worked for me.

Error: an expression of non-boolean type specified in a context where a condition is expected, near ',' ; Using Cascading Parameters

I am trying to use cascading parameters to filter this Pivot table in SSRS Report Builder.
This is the main dataset query:
SELECT * FROM(
SELECT *,
CASE WHEN PLN=PLN THEN '01. GROSS PREMIUM'
ELSE NULL
END AS PREMIUM
FROM MYI
PIVOT (SUM(GROSS_PREMIUM_1) FOR PERIOD_TYPE IN([MTD],[YTD],[ITD])) pvt
UNION ALL
SELECT *,
CASE WHEN PLN=PLN THEN '02. REFUND'
ELSE NULL
END AS PREMIUM
FROM MYI
PIVOT (SUM(REFUND_2) FOR PERIOD_TYPE IN([MTD],[YTD],[ITD])) pvt
)A
WHERE ACC_PERIOD = #ACC_PERIOD
AND REINSURER IN (#REINSURER)
AND INSURER IN (#INSURER)
AND PLN IN (#PLN)
AND SVC_AGY IN (#SVC_AGY)
These parameters in the WHERE clause each have their own dataset and are cascaded from top to bottom.
Here is the query for the final parameter as an example:
SELECT DISTINCT [fasren_servicingagency]
FROM [FAS_ReinsuranceNumber]
WHERE ACC_PERIOD = #ACC_PERIOD
AND REINSURER IN (#REINSURER)
AND INSURER IN (#INSURER)
AND PLN IN (#PLN)
ORDER BY SVC_AGY
The query runs fine in SSMS, but I keep getting this error when I run it in the SSRS report builder:
An expression of non-boolean type specified in a context where a condition is expected, near ','
It must have something to do with the WHERE clause in either the main query or the parameter dataset queries. I have seen many posts about this error but I could not find a solution that helped with my problem. Any ideas?
NOTE: all parameters are character fields, no integers, no date columns.
EDIT: There is another query that I was successful with;
SELECT [acctyymm],
[retrosummary],
[retroagent],
[coveragedivision],
[policyinsurer],
SUM([NetDue]) AS NET_DUE,
SUM([ActualPayable]) AS PAYABLE
FROM [dbo].[RetroNumberGAAP]
WHERE [acctyymm] IN (#ACC_PERIOD)
AND [retrosummary] IN (#RETSUM)
AND [retroagent] IN (#RETAGT)
AND [coveragedivision] IN (#PLN)
AND [policyinsurer] IN (#INSURER)
AND POWER([fasrtng_NetDue],2)+POWER([ActualPayable],2)<>0
GROUP BY [acctyymm],
[retrosummary],
[retroagent],
[coveragedivision],
[policyinsurer]
How am I successful running the report with cascaded parameters in this second query and not the first query?
I figured out what I did wrong. My Dataset properties were not configured correctly in the Report Builder.
WRONG CONFIGURATION
Dataset properties; Parameters; parameter name: SVC_AGY Parameter Value: [#SVC_AGY]
CORRECTED CONFIGURATION
Dataset properties; Parameters; parameter name: #SVC_AGY Parameter Value: [#SVC_AGY]
Make sure your parameter names match your parameter values, including the # symbol.

CAST error in a Where Clause

On the query below I keep getting this error:
Cannot read the next data row for the dataset DataSetProject. (rsErrorReadingNextDataRow)
It appears to be the where clause, if I take it out it seems to work. So I added a cast to the where clause with no luck. Is there something special I need to do in the where clause to get this to work? Just an FYI this is in a report that is pulling an id from the url.
SELECT new_projects.new_projectsId AS ProjectId
, new_projects.new_name AS ProjectName
, new_projects.new_Description AS ProjectDescription
FROM
new_projects
LEFT OUTER JOIN new_projectsteps
ON new_projects.new_projectsId = new_projectsteps.new_ProjectSteps2Id
LEFT OUTER JOIN Task
ON new_projectsteps.new_projectstepsId = Task.RegardingObjectId
WHERE
(new_projects.new_projectsId = cast(#id AS UNIQUEIDENTIFIER))
Thanks!
EDIT:
The id in SQL is a Unique Identifier, the value of #id is being pulled from the querystring(url). So it would look like: &id='BC02ABC0-A6A9-E111-BCAD-32B731EEDD84'
Sorry for the missing info.
I suspect the single quotes are coming through. So either don't have them there by stripping them out before being passed to your parameter or use:
WHERE new_projects.new_projectsId = CONVERT(UNIQUEIDENTIFIER, REPLACE(#id, '''', ''));
If you try a direct comparison when the GUID contains other characters, you should get:
Msg 8169, Level 16, State 2, Line 1 Conversion failed when
converting from a character string to uniqueidentifier.
If this is not what's happening, then don't say "the id in SQL is a Unique Identifier" - show ALL of the code so we can try to reproduce the problem.

NHibernate group by named parameters doesn't work with repeated parameters

My query in HQL is basically:
select functionA(a, :paramA), functionB(b, :paramB), functionC(c, :paramC), sum(d)
from tableA
groupby by functionA(a, :paramA), functionB(b, :paramB), functionC(c, :paramC)
However this gets turned into SQL of
select functionA(a, #param0), functionB(b, #param1), functionC(c, #param2), sum(d)
from tableA
groupby by functionA(a, #param3), functionB(b, #param4), functionC(c, #param5)
Now obviously this is going to throw a 'blah' is invalid in the select list because.... error as the group by clause doesn't match the select clause. I'm about to change this to a string format so I can get on with some productive work but if anyone has the answer as to why NHibernate will not reuse the same named query input the 2 times it is used that would be much appreciated.
A similar question seems to have been asked here with no real answer either.
This has been solved in NHibernate 3.0.0.Alpha1. You can get it here

Resources