![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I have the following MDX query that is working as a sample SELECT * FROM OPENQUERY(OLAP, 'Select ({[Measures].[Avg Revenue], [Measures].[Avg Ad Price]}) on columns, nonemptycrossjoin({[Time].children},{[Sales Region].[All Sales Region].children}) on rows from [Total Revenue]' ) How can I pass in a variable to return the value? Meaning, I want to pass in a Time frame or a Sales Region to get my value which is the avg revenue for that particular region and time period. I'm not sure how to declare a variable and pass it in and return it to the application. |
#3
| |||
| |||
|
|
Try this, In your stored procedure write the query as dynamic sql and then pass the necessary parameters. declare @strSQL varchar(8000) declare @strFromDate datetime declare @strToDate datetime set @strFromDate = '2006-01-01 00:00:00' set @strToDate = '2006-06-01 00:00:00' set @strSQL = 'SELECT * FROM OPENQUERY(OLAP, ''With set [TimeRange] as ''''[Time].[<date level of your time dimension>].&[' + Convert(Varchar(10), @strFromDate, 101) + ']:[Time].[<date level of your time dimension>].&[' + Convert(Varchar(10), @strEndDate, 101) + ']'''' Select ({[Measures].[Avg Revenue], [Measures].[Avg Ad Price]}) on columns, nonemptycrossjoin({[Time].children},{[Sales Region].[All Sales Region].children}) on rows from [Total Revenue]' )'')' exec @strSQL HTH Milind SAM wrote: I have the following MDX query that is working as a sample SELECT * FROM OPENQUERY(OLAP, 'Select ({[Measures].[Avg Revenue], [Measures].[Avg Ad Price]}) on columns, nonemptycrossjoin({[Time].children},{[Sales Region].[All Sales Region].children}) on rows from [Total Revenue]' ) How can I pass in a variable to return the value? Meaning, I want to pass in a Time frame or a Sales Region to get my value which is the avg revenue for that particular region and time period. I'm not sure how to declare a variable and pass it in and return it to the application. |
#4
| |||
| |||
|
|
Try this, In your stored procedure write the query as dynamic sql and then pass the necessary parameters. declare @strSQL varchar(8000) declare @strFromDate datetime declare @strToDate datetime set @strFromDate = '2006-01-01 00:00:00' set @strToDate = '2006-06-01 00:00:00' set @strSQL = 'SELECT * FROM OPENQUERY(OLAP, ''With set [TimeRange] as ''''[Time].[<date level of your time dimension>].&[' + Convert(Varchar(10), @strFromDate, 101) + ']:[Time].[<date level of your time dimension>].&[' + Convert(Varchar(10), @strEndDate, 101) + ']'''' Select ({[Measures].[Avg Revenue], [Measures].[Avg Ad Price]}) on columns, nonemptycrossjoin({[Time].children},{[Sales Region].[All Sales Region].children}) on rows from [Total Revenue]' )'')' exec @strSQL HTH Milind SAM wrote: I have the following MDX query that is working as a sample SELECT * FROM OPENQUERY(OLAP, 'Select ({[Measures].[Avg Revenue], [Measures].[Avg Ad Price]}) on columns, nonemptycrossjoin({[Time].children},{[Sales Region].[All Sales Region].children}) on rows from [Total Revenue]' ) How can I pass in a variable to return the value? Meaning, I want to pass in a Time frame or a Sales Region to get my value which is the avg revenue for that particular region and time period. I'm not sure how to declare a variable and pass it in and return it to the application. |
#5
| |||
| |||
|
|
I got this error message: (OLAP, 'With set [TimeRange] as ''[Time].[All Time].&[05/01/2006]:[Time].[All Time].&[05/30/2006]'' Select ({[Measures].[Avg Revenue], [Measures].[Avg Ad Price]}) on columns, nonemptycrossjoin({[Time].children},{[Sales Region].[All Sales Region].children}) on rows from [Total Revenue]' is not a valid identifier. "Milind" wrote: Try this, In your stored procedure write the query as dynamic sql and then pass the necessary parameters. declare @strSQL varchar(8000) declare @strFromDate datetime declare @strToDate datetime set @strFromDate = '2006-01-01 00:00:00' set @strToDate = '2006-06-01 00:00:00' set @strSQL = 'SELECT * FROM OPENQUERY(OLAP, ''With set [TimeRange] as ''''[Time].[<date level of your time dimension>].&[' + Convert(Varchar(10), @strFromDate, 101) + ']:[Time].[<date level of your time dimension>].&[' + Convert(Varchar(10), @strEndDate, 101) + ']'''' Select ({[Measures].[Avg Revenue], [Measures].[Avg Ad Price]}) on columns, nonemptycrossjoin({[Time].children},{[Sales Region].[All Sales Region].children}) on rows from [Total Revenue]' )'')' exec @strSQL HTH Milind SAM wrote: I have the following MDX query that is working as a sample SELECT * FROM OPENQUERY(OLAP, 'Select ({[Measures].[Avg Revenue], [Measures].[Avg Ad Price]}) on columns, nonemptycrossjoin({[Time].children},{[Sales Region].[All Sales Region].children}) on rows from [Total Revenue]' ) How can I pass in a variable to return the value? Meaning, I want to pass in a Time frame or a Sales Region to get my value which is the avg revenue for that particular region and time period. I'm not sure how to declare a variable and pass it in and return it to the application. |
#6
| |||
| |||
|
|
Comment out exec @strQuery and add this line before that Print @strQuery. Please paste the output that you get in query analyzer. I think you are missing a single quotes somewhere. Milind SAM wrote: I got this error message: (OLAP, 'With set [TimeRange] as ''[Time].[All Time].&[05/01/2006]:[Time].[All Time].&[05/30/2006]'' Select ({[Measures].[Avg Revenue], [Measures].[Avg Ad Price]}) on columns, nonemptycrossjoin({[Time].children},{[Sales Region].[All Sales Region].children}) on rows from [Total Revenue]' is not a valid identifier. "Milind" wrote: Try this, In your stored procedure write the query as dynamic sql and then pass the necessary parameters. declare @strSQL varchar(8000) declare @strFromDate datetime declare @strToDate datetime set @strFromDate = '2006-01-01 00:00:00' set @strToDate = '2006-06-01 00:00:00' set @strSQL = 'SELECT * FROM OPENQUERY(OLAP, ''With set [TimeRange] as ''''[Time].[<date level of your time dimension>].&[' + Convert(Varchar(10), @strFromDate, 101) + ']:[Time].[<date level of your time dimension>].&[' + Convert(Varchar(10), @strEndDate, 101) + ']'''' Select ({[Measures].[Avg Revenue], [Measures].[Avg Ad Price]}) on columns, nonemptycrossjoin({[Time].children},{[Sales Region].[All Sales Region].children}) on rows from [Total Revenue]' )'')' exec @strSQL HTH Milind SAM wrote: I have the following MDX query that is working as a sample SELECT * FROM OPENQUERY(OLAP, 'Select ({[Measures].[Avg Revenue], [Measures].[Avg Ad Price]}) on columns, nonemptycrossjoin({[Time].children},{[Sales Region].[All Sales Region].children}) on rows from [Total Revenue]' ) How can I pass in a variable to return the value? Meaning, I want to pass in a Time frame or a Sales Region to get my value which is the avg revenue for that particular region and time period. I'm not sure how to declare a variable and pass it in and return it to the application. |
#7
| |||
| |||
|
|
Comment out exec @strQuery and add this line before that Print @strQuery. Please paste the output that you get in query analyzer. I think you are missing a single quotes somewhere. Milind SAM wrote: I got this error message: (OLAP, 'With set [TimeRange] as ''[Time].[All Time].&[05/01/2006]:[Time].[All Time].&[05/30/2006]'' Select ({[Measures].[Avg Revenue], [Measures].[Avg Ad Price]}) on columns, nonemptycrossjoin({[Time].children},{[Sales Region].[All Sales Region].children}) on rows from [Total Revenue]' is not a valid identifier. "Milind" wrote: Try this, In your stored procedure write the query as dynamic sql and then pass the necessary parameters. declare @strSQL varchar(8000) declare @strFromDate datetime declare @strToDate datetime set @strFromDate = '2006-01-01 00:00:00' set @strToDate = '2006-06-01 00:00:00' set @strSQL = 'SELECT * FROM OPENQUERY(OLAP, ''With set [TimeRange] as ''''[Time].[<date level of your time dimension>].&[' + Convert(Varchar(10), @strFromDate, 101) + ']:[Time].[<date level of your time dimension>].&[' + Convert(Varchar(10), @strEndDate, 101) + ']'''' Select ({[Measures].[Avg Revenue], [Measures].[Avg Ad Price]}) on columns, nonemptycrossjoin({[Time].children},{[Sales Region].[All Sales Region].children}) on rows from [Total Revenue]' )'')' exec @strSQL HTH Milind SAM wrote: I have the following MDX query that is working as a sample SELECT * FROM OPENQUERY(OLAP, 'Select ({[Measures].[Avg Revenue], [Measures].[Avg Ad Price]}) on columns, nonemptycrossjoin({[Time].children},{[Sales Region].[All Sales Region].children}) on rows from [Total Revenue]' ) How can I pass in a variable to return the value? Meaning, I want to pass in a Time frame or a Sales Region to get my value which is the avg revenue for that particular region and time period. I'm not sure how to declare a variable and pass it in and return it to the application. |
#8
| |||
| |||
|
#9
| |||
| |||
|
|
ok finally I was able to get a little farther with the following but still not quite there yet: DECLARE @sql varchar(8000) Declare @time datetime Declare @region varchar(2000) set @time = '2006-05-01 00:00:00' set @region = 'Georgia' SET @sql = 'SELECT * FROM OPENQUERY(OLAP, ''Select ({[Measures].[Avg Revenue]}) on columns From [Total Revenue] Where [Time].[All Time].member = ''''+ Convert(varchar(10), @time,101) +'''' '')' Here is the result: Server: Msg 7321, Level 16, State 2, Line 1 An error occurred while preparing a query for execution against OLE DB provider 'MSOLAP'. [OLE/DB provider returned message: Syntax error, expecting end of statement but found extra text, near: '= '+ Convert(varchar(10), @time,101) +' '] OLE DB error trace [OLE/DB Provider 'MSOLAP' ICommandPrepare::Prepare returned 0x80040e14]. |
#10
| |||
| |||
|
|
Server: Msg 7321, Level 16, State 2, Line 1 An error occurred while preparing a query for execution against OLE DB provider 'MSOLAP'. [OLE/DB provider returned message: Syntax error in expression, near: ''[Time].[05/01/2006] "SAM" wrote: ok finally I was able to get a little farther with the following but still not quite there yet: DECLARE @sql varchar(8000) Declare @time datetime Declare @region varchar(2000) set @time = '2006-05-01 00:00:00' set @region = 'Georgia' SET @sql = 'SELECT * FROM OPENQUERY(OLAP, ''Select ({[Measures].[Avg Revenue]}) on columns From [Total Revenue] Where [Time].[All Time].member = ''''+ Convert(varchar(10), @time,101) +'''' '')' Here is the result: Server: Msg 7321, Level 16, State 2, Line 1 An error occurred while preparing a query for execution against OLE DB provider 'MSOLAP'. [OLE/DB provider returned message: Syntax error, expecting end of statement but found extra text, near: '= '+ Convert(varchar(10), @time,101) +' '] OLE DB error trace [OLE/DB Provider 'MSOLAP' ICommandPrepare::Prepare returned 0x80040e14]. |
![]() |
| Thread Tools | |
| Display Modes | |
| |