SQL OpenRowset - object has no columns - sql

I have a dynamically Stored Procedure, which create a mdx statement for a OpenRowset Query. So it can happen that the objects from the mdx statement are empty. In this case I want back an empty string
SQL Server gives me this error:
"The OLE DB provider "" for linked server "(null)" indicates that either the object has no columns or the current user does not have permissions on that object."
I tried different things (Catch Statement, sp_describe_first_result_set) but nothing was working...
How can I handle this error ? In my statement below ie. the customer 'Abbas' is not available...
SELECT A.* FROM OpenRowset('MSOLAP', 'DATASOURCE=.; Initial Catalog=CUBE','
SELECT
{[Dim Customer].[v Dim Customer Name].[Customer].&[Abbas]} *
{[Dim Salesperson].[Lastname].&[Fima 1]} *
{[Dim Creditcard].[v Dim Creditcard Cardtype].[Cardtype].&[Vista]} ON 0
FROM CUBE
WHERE [Measures].[total]
') as A

Please try putting measures on columns and dimensions on rows:
SELECT A.* FROM OpenRowset('MSOLAP', 'DATASOURCE=.; Initial Catalog=CUBE','
SELECT {[Measures].[total]} ON 0,
{[Dim Customer].[v Dim Customer Name].[Customer].&[Abbas]} *
{[Dim Salesperson].[Lastname].&[Fima 1]} *
{[Dim Creditcard].[v Dim Creditcard Cardtype].[Cardtype].&[Vista]} ON 1
FROM CUBE
') as A

Related

Deeply nested recursive calculations cannot invoke a CLR Stored Procedure

I hit the above error message when running the below query:
WITH
MEMBER [Measures].[LEVEL INSTANCE none:Date:qk - lev00] AS
'CASE WHEN IsEmpty([Dim Calendar].[Date].CurrentMember.MemberValue) OR [Dim Calendar].[Date].CurrentMember.MemberValue = null THEN null ELSE CDate([Dim Calendar].[Date].CurrentMember.MemberValue) END',
SOLVE_ORDER = 127
SELECT
{[Measures].[AvgSelectedCount],
[Measures].[AvgSelectedScore]} DIMENSION PROPERTIES [MEMBER_UNIQUE_NAME],[MEMBER_CAPTION] ON COLUMNS,
NON EMPTY [Dim Calendar].[Year].[Year].AllMembers DIMENSION PROPERTIES [MEMBER_UNIQUE_NAME],[MEMBER_CAPTION] ON ROWS
FROM [sqis]
WHERE
StripCalculatedMembers(CROSSJOIN(
Filter(
[Dim Calendar].[Date].[Date].AllMembers,
DATEADD("d",-365,DATEADD("d",DATEDIFF("d",CDate(36526),NOW()),CDate(36526))) <= [Measures].[LEVEL INSTANCE none:Date:qk - lev00] AND [Measures].[LEVEL INSTANCE none:Date:qk - lev00] < DATEADD("d",1,DATEADD("d",DATEDIFF("d",CDate(36526),NOW()),CDate(36526)))),
{[Dim Country Region Vendor].[Country].&[Italy]}))
Query (14, 5) Execution of the managed stored procedure DATEADD failed
with the following error:
Microsoft::AnalysisServices::AdomdServer::AdomdException. Deeply
nested recursive calculations cannot invoke a CLR Stored Procedure.
Execution complete
What is the meaning of the error and is there anything that needs to be set for DimCalendar Date properties in SSAS?

MDX results to Excel in Power Pivot

I don't know ABCDs of MDX. I have this query that was handed over to me by my predecessor and that it is needed only once in a year! That time of the year happens to be now! The query runs and returns the results. However, I am unable to copy the result along with the rows and column names from the SSAS result window.
Googling I found the options of Linked servers, setting query options to save the result as csv etc, using SSIS packages and PowerPivot.
The first two are not possible because of restrictions on the DB. I need to go over a bunch of corporate hurdles to get the necessary permissions.
SSIS packages and Power Pivot - have the same issue. 'BUD' is a named set and it is referenced in the filter below in select statement. Both SSIS (when typed in OLEDB Source) throws error - The dimension [BUD] was not found.
Working with PowerPivot, I executed set create statement separately and then pasted only the code after 'WITH'. The Error was -The dimension [BUD] was not found.
Any help of how to reference the BUD in the select statement for Power Pivot or SSIS? I am using sqlsever2008r2.
This the procedure -
create set [DB1].BUD AS
nonemptycrossjoin(
{[Market].[Markets].&[Europe].children,[Market].[Markets].[Part of World].&[Africa].children},
[Product].[PL].&[CD] : [Product].[PL].&[KZ],
[Plant].[Plant].children
) go
with
member measures.callsCY1 as
/* Lot of measure calutaions here */
select
non empty
{
[Measures].[Qty Sold],
callsCY1,costCY1,MTRLcostCY1,LabourCostCY1,
SCR_C,callsRY1,costRY1,MTRLcostRY1,LabourCostRY1,
callsCY2,costCY2,MTRLcostCY2,LabourCostCY2,
callsRY2,costRY2,MTRLcostRY2,LabourCostRY2,
callsCY3,costCY3,MTRLcostCY3,LabourCostCY3,
callsRY3,costRY3,MTRLcostRY3,LabourCostRY3
}
*
{[Report Period].[Report Periods].[Quarter].&[2013-01-01T00:00:00] : [Report Period].[Report Periods].[Quarter].&[2014-06-01T00:00:00]}
on 0,
non empty
filter(
bud, [Measures].[Qty Sold] <> 0 OR [Measures].[QTY Service Calls] <> 0)
on 1
from [db1]
Does bud need to be seperate? Can't you just use this?
with
set [BUD] AS
nonemptycrossjoin(
{[Market].[Markets].&[Europe].children,[Market].[Markets].[Part of World].&[Africa].children},
[Product].[PL].&[CD] : [Product].[PL].&[KZ],
[Plant].[Plant].children
)
member measures.callsCY1 as
/* Lot of measure calutaions here */
select
non empty
{
[Measures].[Qty Sold],
callsCY1,costCY1,MTRLcostCY1,LabourCostCY1,
SCR_C,callsRY1,costRY1,MTRLcostRY1,LabourCostRY1,
callsCY2,costCY2,MTRLcostCY2,LabourCostCY2,
callsRY2,costRY2,MTRLcostRY2,LabourCostRY2,
callsCY3,costCY3,MTRLcostCY3,LabourCostCY3,
callsRY3,costRY3,MTRLcostRY3,LabourCostRY3
}
*
{[Report Period].[Report Periods].[Quarter].&[2013-01-01T00:00:00] : [Report Period].[Report Periods].[Quarter].&[2014-06-01T00:00:00]}
on 0,
non empty
filter(
bud, [Measures].[Qty Sold] <> 0 OR [Measures].[QTY Service Calls] <> 0)
on 1
from [db1]

how to set caption for calculated measure in MDX

i have a MDX query in Mondrian like below
with member [Measures].[a] as '([Measures].[LCount] * 2)'
member [Measures].[b] as '([Measures].[a] * 3)'
select {[Rate].[Rate].Members} ON COLUMNS,
{[Measures].[a], [Measures].[b]} ON ROWS
from [c];
and i want to set caption for my calculated measures that is different with their uniqeName
what should i do?
NOTICE :
with member [Measures].[a] as '([Measures].[LCount] * 2)',
CAPTION = "my measure"
doesn't work!
I tried a statement similar to
with member [Measures].[a] as '([Measures].[Internet Sales Amount] * 2)', Caption = 'my measure'
member [Measures].[b] as '([Measures].[a] * 3)'
select {[Customer].[Customer Geography].[Country].members} ON COLUMNS,
{[Measures].[a], [Measures].[b]} ON ROWS
from [Adventure Works];
and it worked without problems. Note: I used single quotes for the caption text.
Just a remark unrelated to this: You can omit the quotes around the member definition if you do not need compatibility with Analysis Services in the 2000 version. This sometimes (but not in this case) gives you better syntax error messages.

MDX CREATE MEMBER SYNTAX ERROR?

I'm very new to MDX, so sorry if this is a stupid question.
I'm creating a new calculated member
I'm getting a syntax error on Line 2 "AS SELECT NON EMPTY"?
CREATE MEMBER CURRENTCUBE.[Measures].FCR
AS SELECT NON EMPTY { [Measures].[Total Incident Count] } ON COLUMNS
FROM ( SELECT ( { [DIM INCIDENT].[First Call Resolution].&[Yes] } ) ON COLUMNS
FROM [ITSM Incident DM])
WHERE ( [DIM INCIDENT].[First Call Resolution].&[Yes] ),
FORMAT_STRING = "Standard",
VISIBLE = 1 ;
Thanks in advance for any assistance.
You cannot put a Select statement in the expression of a calculated member.
You can fine more information on this MSDN page.

SQL Error in VBA

I have the following code in SQL (2005) which calculates the avarage user logins on a systm:
with
user_total as
(
select COUNT(distinct ID) as counter
FROM [dbo].[LOG]
where [LOG].DESCRIPTION='Login success.'
AND
Convert(datetime,convert(char(10),[LOG].CREATED_ON,101)) BETWEEN '2009-01- 01' AND '2009-12-31'
),
USER_avg as
(
select counter/365 as Avarage_Daily_Logins
from user_total
)
select *
from USER_avg
Now the problem is when i put this in a VBA macro in excel to get the result in a spcific cell in strSQL = "QUERY SHOWN ABOVE HERE" argument i get the error in excel
incorrect sysntax near the keyword with
Its worth mentioning that i dont break the code in VBA in multiple lines..i have it all in one line.
Use ;WITH ...
WITH usage for a CTE must have ; after the previous statement. To ensure this is the cases, prefix with ;
Check all of your spacings, if there is an error further down the compiler may interpret it as a problem with the with statement.