I want to use stored procedure to fill my JqGrid. My stored procedure is below:
ALTER PROCEDURE [dbo].[SubJqGridObisDataSP]
as begin
DECLARE @header AS NVARCHAR(MAX),@MetID AS bigint
SELECT @header =
STUFF((SELECT ',' + QUOTENAME([ObisInfoTranslateT])
from MetContDB.dbo.tblMet AS met
join MetContDB.dbo.tblMod AS mod on mod.ModID= met.ModID_FK
join MetContDB.dbo.tblGroupData As Gro on Gro.MetID_FK= met.MetID
join MetContDB.dbo.tblObisData as obisdata on obisdata.GroupDataID_FK=Gro.GroupDataID
join MetContDB.dbo.tblObisInfo AS obisinfo on obisinfo.ObisInfoID=obisdata.ObisInfoID_FK
join (select max(GroupDataID) as maxgroupdata from MetContDB.dbo.tblGroupData where MetID_FK=@MetID) g on Gro.GroupDataID=g.maxgroupdata
where met.MetID=@MetID
FOR XML PATH(''), TYPE
).value('.', 'NVARCHAR(MAX)')
,1,1,'')
DECLARE @DynamicPIVOT AS NVARCHAR(MAX)
SELECT @DynamicPIVOT = 'SELECT ' + @header +
' FROM (
select
obisdata.ObisData,
obisinfo.[ObisInfoTranslateT]
from MetContDB.dbo.tblMet AS met
join MetContDB.dbo.tblMod AS mod on mod.ModID= met.ModID_FK
join MeterControlDB.dbo.tblGroupData As Gro on Gro.MetID_FK= met.MetID
join MetContDB.dbo.tblObisData as obisdata on obisdata.GroupDataID_FK=Gro.GroupDataID
join MetContDB.dbo.tblObisInfo AS obisinfo on obisinfo.ObisInfoID=obisdata.ObisInfoID_FK
join(select
max(GroupDataID) as maxgroupdata
from MeterControlDB.dbo.tblGroupData
where MetID_FK=@MetID) g on Gro.GroupDataID=g.maxgroupdata
where met.MetID=@MetID) Books
PIVOT (MAX(ObisData) FOR [ObisInfoTranslateT] IN (' + @header + ')) Result;'
EXEC (@DynamicPIVOT)
end
But when i use this SP in my controller, I get error : output of Stored procedure is int????? My output stored procedure is some row. controller:
MetContDBEntities ctnx = new MetContDBEntities();
var obisDatas = ctnx.SubJqGridObisDataSP(id).ToList();
my code before query is:
select obisdata.ObisData,obisinfo.ObisInfoTranslateT
from MetContDB.dbo.tblMet AS met
join MetContDB.dbo.tblMod AS mod on mod.ModID= met.ModID_FK
join MetContDB.dbo.tblGroupData As Gro on Gro.MetID_FK= met.MetID
join MetContDB.dbo.tblObisData as obisdata on obisdata.GroupDataID_FK=Gro.GroupDataID
join MetContDB.dbo.tblObisInfo AS obisinfo on obisinfo.ObisInfoID=obisdata.ObisInfoID_FK
join(select
max(GroupDataID) as maxgroupdata
from MetContDB.dbo.tblGroupData
where MetID_FK=39) g on Gro.GroupDataID=g.maxgroupdata
where met.MetID=39
Output of this:
I want to show like this:
With first query I can change pic1 to pic2 .