Query a stored procedure that exec's a dynamic query. Error Linked server indicates object has no columns -



Query a stored procedure that exec's a dynamic query. Error Linked server indicates object has no columns -

i have stored procedure dynamically creates pivot query.

the procedure works , returns right data.

now have requirement show info in reporting scheme can pull table or view. since can not create dynamic query in view tried select using openquery.

example '

select * openquery([myservername], 'exec instance.schema.storedprocedure')

i error

"the linked server indicates object has no columns".

i assume because of first select statement stuffing variable column names.

code procedure

alter procedure [dbo].[fuelcombustormatrix] begin -- utilize master set nocount on declare @cols nvarchar(2000), @tcols nvarchar(2000), @sql nvarchar (max) select @cols = stuff (( select distinct '], ['+modelname + ' ' + combustorname combustorfuel cf bring together model m on cf.modelid = m.modelid bring together combustors cb on cf.combustorid = cb.combustorid cf.combustorid > 0 xml path('') ),1,2,'')+']' set @tcols = replace(@cols, ']', '] int') --print @tcols --print @cols set @sql = 'select gasliquid, fueltype, '+ @cols +' ( select gasliquid, fueltype, modelname+ '' '' +combustorname modelcombustor, combfuelstatus+''- ''+combfuelnote combfuelstatusnote frames f bring together family fa on f.frameid = fa.frameid bring together model m on fa.familyid = m.familyid bring together combustorfuel cf on m.modelid = cf.modelid bring together combustors c on cf.combustorid = c.combustorid bring together fueltypes ft on cf.fueltypeid = ft.fueltypeid cf.combustorfuelid > 0 , combustorname <> '''' ) pivot (max(combfuelstatusnote) modelcombustor in ('+ @cols +')) pvt order fueltype' exec (@sql) end

sql-server sql-server-2008 tsql stored-procedures

Comments

Popular posts from this blog

c - Compilation of a code: unkown type name string -

java - Bypassing "final local variable defined in an enclosing type" -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -