Openquery to Oracle in execute

miral13
miral13 used Ask the Experts™
on
I am trying to run an openquery via an oracle linked server but I get this error:
'Could not find stored procedure 'select * from openquery(UKORACLE, ''select  to_char(ID) as ID from VW_DATA'')'

If I execute the query without putting it in an execute then it works.

Thanks

declare @sql as varchar(4000)
set @sql = '
select *
from openquery(UKORACLE, ''select
    to_char(ID) as ID
	from VW_DATA'')'
 
exec @sql

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Billing Engineer
Most Valuable Expert 2014
Top Expert 2009
Commented:
change:
exec @sql

into:
exec (@sql)

Author

Commented:
Brilliant of you and stupid of me, thanks!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial