sqlserver 存储过程 返回结果集的 例子

本人不会在sqlserver存储过程返回结果集,请大家指教如何写这样的存储过程。能给出代码的例子吗?我明白,主要是不知道怎么写... 本人不会在 sqlserver 存储过程 返回结果集 ,请大家指教如何写这样的存储过程。
能给出代码的例子吗?
我明白,主要是不知道怎么写
展开
 我来答
百度网友9669419a2
2008-11-26 · TA获得超过316个赞
知道小有建树答主
回答量:105
采纳率:0%
帮助的人:99.5万
展开全部
返回结果集不用Output,直接Select出来的结果集就能返回
在应用程序或网页程序中用你调用存储过程的这个对象像普通记录集一个调用就好了
如果是在查询分析器中执行,可以在下面的“网格”中直接看到返回的这个结果集
sytdeedee
2008-11-26 · TA获得超过442个赞
知道小有建树答主
回答量:694
采纳率:0%
帮助的人:622万
展开全部
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE AIR_RPT_Report5
( @Year varchar(10)= '2008',
@Month Varchar(10)= '03' ,
@SQLWhere VARCHAR(2000)
)
AS
BEGIN

EXEC('SELECT IB_ID,''AIR'' AS SYSTEMID,
sum(case when RP_INDICATOR=''R'' AND CUR_ID IN(''USD'',''CNY'',''EUR'',''GBP'') then ISNULL(AMT,0) else 0 end ) as AMT_R,
sum(case when RP_INDICATOR=''P'' AND CUR_ID IN(''USD'',''CNY'',''EUR'',''GBP'') then ISNULL(AMT,0) else 0 end ) as AMT_P,
sum(case when CUR_ID=''USD'' AND RP_INDICATOR=''R'' then BLAMT else 0 end ) as AMT_R_USD,
sum(case when CUR_ID=''USD'' AND RP_INDICATOR=''P'' then BLAMT else 0 end ) as AMT_P_USD,
sum(case when CUR_ID=''USD'' AND RP_INDICATOR=''R'' AND ARP_TYPE=''AG'' then BLAMT else 0 end ) as AMT_R_USD_AG,
sum(case when CUR_ID=''USD'' AND RP_INDICATOR=''P'' AND ARP_TYPE=''AG'' then BLAMT else 0 end ) as AMT_P_USD_AG,
sum(case when CUR_ID=''EUR'' AND RP_INDICATOR=''R'' AND ARP_TYPE=''AG'' then BLAMT else 0 end ) as AMT_R_EUR,
sum(case when CUR_ID=''EUR'' AND RP_INDICATOR=''P'' AND ARP_TYPE=''AG'' then BLAMT else 0 end ) as AMT_P_EUR,
sum(case when CUR_ID=''GBP'' AND RP_INDICATOR=''R'' AND ARP_TYPE=''AG'' then BLAMT else 0 end ) as AMT_R_GBP,
sum(case when CUR_ID=''GBP'' AND RP_INDICATOR=''P'' AND ARP_TYPE=''AG'' then BLAMT else 0 end ) as AMT_P_GBP,
sum(case when CUR_ID=''CNY'' AND RP_INDICATOR=''R'' AND ARP_TYPE<>''AG'' then AMT else 0 end ) as AMT_R_CNY,
sum(case when CUR_ID=''CNY'' AND RP_INDICATOR=''P'' AND ARP_TYPE<>''AG'' then AMT else 0 end ) as AMT_P_CNY,
sum(case when RP_INDICATOR=''R'' AND CUR_ID IN(''USD'',''CNY'',''EUR'',''GBP'') then ISNULL(AMT,0) else 0 end )-
sum(case when RP_INDICATOR=''P'' AND CUR_ID IN(''USD'',''CNY'',''EUR'',''GBP'') then ISNULL(AMT,0) else 0 end ) as AMT_Profit
FROM
( SELECT SUM(AMOUNT) AS BLAMT,SUM(BASE_CUR_AMOUNT) AS AMT,A.CUR_ID,ARP_TYPE,RP_INDICATOR,IB_ID
FROM RP_FRT A
JOIN AIR_BL_PLAN B ON A.BL_ID=B.BL_ID
WHERE BL_TYPE<>''总单'' AND Year(A.INPUT_DATE)='+@Year+' AND month(A.INPUT_DATE)='+@Month +@SQLWhere+
'GROUP BY IB_ID,A.CUR_ID,RP_INDICATOR,ARP_TYPE
) AS B
GROUP BY IB_ID
UNION
SELECT IB_ID,''OCEAN'' AS SYSTEMID,
sum(case when RP_INDICATOR=''R'' AND CUR_ID IN(''USD'',''CNY'',''EUR'',''GBP'') then ISNULL(AMT,0) else 0 end ) as AMT_R,
sum(case when RP_INDICATOR=''P'' AND CUR_ID IN(''USD'',''CNY'',''EUR'',''GBP'') then ISNULL(AMT,0) else 0 end ) as AMT_P,
sum(case when CUR_ID=''USD'' AND RP_INDICATOR=''R'' then BLAMT else 0 end ) as AMT_R_USD,
sum(case when CUR_ID=''USD'' AND RP_INDICATOR=''P'' then BLAMT else 0 end ) as AMT_P_USD,
sum(case when CUR_ID=''USD'' AND RP_INDICATOR=''R'' AND ARP_TYPE=''AG'' then BLAMT else 0 end ) as AMT_R_USD_AG,
sum(case when CUR_ID=''USD'' AND RP_INDICATOR=''P'' AND ARP_TYPE=''AG'' then BLAMT else 0 end ) as AMT_P_USD_AG,
sum(case when CUR_ID=''EUR'' AND RP_INDICATOR=''R'' AND ARP_TYPE=''AG'' then BLAMT else 0 end ) as AMT_R_EUR,
sum(case when CUR_ID=''EUR'' AND RP_INDICATOR=''P'' AND ARP_TYPE=''AG'' then BLAMT else 0 end ) as AMT_P_EUR,
sum(case when CUR_ID=''GBP'' AND RP_INDICATOR=''R'' AND ARP_TYPE=''AG'' then BLAMT else 0 end ) as AMT_R_GBP,
sum(case when CUR_ID=''GBP'' AND RP_INDICATOR=''P'' AND ARP_TYPE=''AG'' then BLAMT else 0 end ) as AMT_P_GBP,
sum(case when CUR_ID=''CNY'' AND RP_INDICATOR=''R'' AND ARP_TYPE<>''AG'' then AMT else 0 end ) as AMT_R_CNY,
sum(case when CUR_ID=''CNY'' AND RP_INDICATOR=''P'' AND ARP_TYPE<>''AG'' then AMT else 0 end ) as AMT_P_CNY,
sum(case when RP_INDICATOR=''R'' AND CUR_ID IN(''USD'',''CNY'',''EUR'',''GBP'') then ISNULL(AMT,0) else 0 end )-
sum(case when RP_INDICATOR=''P'' AND CUR_ID IN(''USD'',''CNY'',''EUR'',''GBP'') then ISNULL(AMT,0) else 0 end ) as AMT_Profit
FROM
( SELECT SUM(AMOUNT) AS BLAMT,SUM(BASE_CUR_AMOUNT) AS AMT,A.CUR_ID,ARP_TYPE,RP_INDICATOR,IB_ID
FROM RP_FRT A
JOIN OC_BL_PLAN B ON A.BL_ID=B.BL_ID
WHERE BL_TYPE<>''MBL'' AND Year(A.INPUT_DATE)='+@Year+' AND month(A.INPUT_DATE)='+@Month +@SQLWhere+
'GROUP BY IB_ID,A.CUR_ID,RP_INDICATOR,ARP_TYPE
) AS B
GROUP BY IB_ID')

END

GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

满意了吗
其实很简单,就是SELECT
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式