Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pass variable to MDX query

Status
Not open for further replies.
Sep 17, 2001
672
US
I am using the openquery function in query analyzer. I have a working query that I would like to use a variable in. I have tried using standard aprroaches but I can't figure out how to get it to work. I tried passing @ variables like in stored procedures. So the question is once I say olap_server, it expects a string but I can't figure how to do variable substitution. Tried " lll" +@Variable etc. Here is a snipet of my code:

SELECT * FROM OPENQUERY(olap_server, @Start]+ [@ItemId]+ ', [Items].[Item Sku] ) }...etc
 
you have to use sp_executesql

select @query= 'SELECT * FROM OPENQUERY(olap_server, '@Start + [@ItemId]+ ', [Items].[Item Sku] ) }...

select @nquery=cast(@query as nvarchar(400))
EXEC sp_executesql @nquery
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top