存储过程如下 if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[PlantHProc]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[PlantHProc]
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE proc [dbo].PlantHProc
(
@PlantTypeID varchar(8000)
)
as
begin
DECLARE @PlantNameS VARCHAR(8000)
SELECT @PlantNameS=''
SELECT @PlantNameS=@PlantNameS+',Max(CASE TPB.PlantName WHEN '''+PlantName+''' THEN TPP.ParamValue ELSE NULL END) AS '+QUOTENAME(PlantName+'|'+PlantModel
+'|'+Manufacture)
FROM (
select TPB.PlantName,TC.FValue,TPP.ParamValue,TPB.PlantModel,TPB.Manufacture
from AM_TPLANTBASEINFO TPB
join AM_TPLANTPARAMS TPP on TPP.PID=TPB.PID
join AM_TCOnfig TC on TC.FType=TPP.PlantTypeGUID and TC.FKey=TPP.ParamItemID
join AM_TConfig TCC on TCC.FKey=TPB.PlantType and TCC.FType='设备类别'
where TCC.Fkey=@PlantTypeID
) a GROUP BY PlantName,PlantModel,Manufacture
exec (
'select TC.FType,TC.FKey,SubString(TC.FValue,0,CharIndex(''|'',TC.FValue,0)) as MaxType,SubString(TC.FValue,CharIndex(''|'',TC.FValue,0)+1,len(TC.Fvalue)-
CharIndex(''|'',TC.FValue,0)) as MinType'+@PlantNameS+'
from AM_TPLANTBASEINFO TPB
join AM_TPLANTPARAMS TPP on TPP.PID=TPB.PID
join AM_TCOnfig TC on TC.FType=TPP.PlantTypeGUID and TC.FKey=TPP.ParamItemID
join AM_TConfig TCC on TCC.FKey=TPB.PlantType and TCC.FType=''设备类别''
where TCC.Fkey='''+@PlantTypeID+''' group by TC.FType,TC.FKey,TC.FValue')
end
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO |