input parameter for sp
, @PageSize INT = 10
, @PageIndex INT = 1
store procedure definitions
SELECT XYZID, XYZType, InCylinder,InSystem,XXXX
FROM (
SELECT XYZes.XYZID
, XYZes.XYZType
, ISNULL((SELECT SUM(TABLEPQR.XYZVolume) FROM TABLEPQR WHERE TABLEPQR.XYZID = XYZes.XYZID AND TABLEPQR.AssetTypeID IN (1, 3) ), 0) AS InCylinder
, ISNULL((SELECT SUM(TABLEPQR.XYZVolume) FROM TABLEPQR WHERE TABLEPQR.XYZID = XYZes.XYZID AND TABLEPQR.AssetTypeID = 2 ), 0) AS InSystem
, ISNULL(
ISNULL((SELECT SUM(TABLEXYZ.XYZVolume) FROM TABLEXYZ WHERE TABLEXYZ.XYZTypeID = XYZes.XYZID AND TABLEXYZ.Activity = 'XXXX'), 0)
+
ISNULL((SELECT SUM(TABLENNN.XYZVolume) FROM TABLENNN WHERE TABLENNN.XYZTypeID = XYZes.XYZID AND TABLENNN.Activity = 'XXXX'), 0)
, 0) AS XXXX,
ROW_NUMBER() OVER (ORDER BY XYZID) AS RowNum
FROM XYZes ) AS SOD
WHERE SOD.RowNum BETWEEN ((@PageIndex-1)*@PageSize)+1
AND @PageSize*(@PageIndex)
select @RecordCount = COUNT(*) From XYZes
return @RecordCount
, @PageSize INT = 10
, @PageIndex INT = 1
store procedure definitions
SELECT XYZID, XYZType, InCylinder,InSystem,XXXX
FROM (
SELECT XYZes.XYZID
, XYZes.XYZType
, ISNULL((SELECT SUM(TABLEPQR.XYZVolume) FROM TABLEPQR WHERE TABLEPQR.XYZID = XYZes.XYZID AND TABLEPQR.AssetTypeID IN (1, 3) ), 0) AS InCylinder
, ISNULL((SELECT SUM(TABLEPQR.XYZVolume) FROM TABLEPQR WHERE TABLEPQR.XYZID = XYZes.XYZID AND TABLEPQR.AssetTypeID = 2 ), 0) AS InSystem
, ISNULL(
ISNULL((SELECT SUM(TABLEXYZ.XYZVolume) FROM TABLEXYZ WHERE TABLEXYZ.XYZTypeID = XYZes.XYZID AND TABLEXYZ.Activity = 'XXXX'), 0)
+
ISNULL((SELECT SUM(TABLENNN.XYZVolume) FROM TABLENNN WHERE TABLENNN.XYZTypeID = XYZes.XYZID AND TABLENNN.Activity = 'XXXX'), 0)
, 0) AS XXXX,
ROW_NUMBER() OVER (ORDER BY XYZID) AS RowNum
FROM XYZes ) AS SOD
WHERE SOD.RowNum BETWEEN ((@PageIndex-1)*@PageSize)+1
AND @PageSize*(@PageIndex)
select @RecordCount = COUNT(*) From XYZes
return @RecordCount
No comments:
Post a Comment