sql存储过程 貌似进入死循环了,不知道为什么

DECLAREtocdCurSCROLLCURSORFORSELECTBussinessPartnerMaster.BP_ID,SalesOrder.[SECTION],... DECLARE tocdCur SCROLL CURSOR FOR
SELECT BussinessPartnerMaster.BP_ID,SalesOrder.[SECTION],
BussinessPartnerMaster.BILL_BP_ID,BussinessPartnerMaster.PAY_MONTH,
BussinessPartnerMaster.PAY_DAY
FROM BussinessPartnerMaster
LEFT OUTER JOIN SalesOrder
ON BussinessPartnerMaster.BP_ID=SalesOrder.CUSTOMER
WHERE BussinessPartnerMaster.BILL_TYPE=@BILL_TYPE
AND BussinessPartnerMaster.CLOSING_DAY=@CLOSING_DAY
/*AND BussinessPartnerMaster.BP_ID=(CASE WHEN @TOKCD ='' THEN BussinessPartnerMaster.BP_ID
ELSE @TOKCD END)*/
and BussinessPartnerMaster.BP_ID='167301'
GROUP BY BussinessPartnerMaster.BP_ID,SalesOrder.[SECTION],
BussinessPartnerMaster.BILL_BP_ID,BussinessPartnerMaster.PAY_MONTH,
BussinessPartnerMaster.PAY_DAY
OPEN tocdCur
FETCH tocdCur INTO @BP_ID, @SECTION, @BILL_BP_ID, @PAY_MONTH, @PAY_DAY
WHILE (@@FETCH_STATUS=0)
BEGIN
INSERT INVOICE_DETAIL(
[SECTION],CUSTOMER,BILL_BP_ID,
CLOSING_DAY,PRE_CLOSING_DAY,
PAY_DAY,PRE_AMOUNT_BILL,
RECEIPT_AMOUNT,SALES_AMOUNT,
DISCOUNT_RETURN,TAX_AMOUT,
AMOUNT_BILL
) VALUES
(@SECTION,@BP_ID,@BILL_BP_ID,
@CLOSING_DATE,@maxdate,
@plndate,@AMOUNT_BILL,
@receam,@pSALES_AMOUNT,
@mSALES_AMOUNT,@taxam,
@amount)
END
CLOSE tocdCur
DEALLOCATE tocdCur
额,解决掉了,循环内没写FETCH tocdCur INTO @BP_ID, @SECTION, @BILL_BP_ID, @PAY_MONTH, @PAY_DAY
展开
 我来答
  • 你的回答被采纳后将获得:
  • 系统奖励15(财富值+成长值)+难题奖励10(财富值+成长值)+提问者悬赏50(财富值+成长值)
SQL的艺术
2015-10-09 · SQL写多了就会在追求极致
SQL的艺术
采纳数:2040 获赞数:3323

向TA提问 私信TA
展开全部
完全可以不用这样写,效率太低下了
追问
额,那怎么写
追答
INSERT into INVOICE_DETAIL(
          [SECTION],CUSTOMER,BILL_BP_ID,
          CLOSING_DAY,PRE_CLOSING_DAY,
          PAY_DAY,PRE_AMOUNT_BILL,
          RECEIPT_AMOUNT,SALES_AMOUNT,
          DISCOUNT_RETURN,TAX_AMOUT,
          AMOUNT_BILL)
SELECT BussinessPartnerMaster.BP_ID,SalesOrder.[SECTION],
    BussinessPartnerMaster.BILL_BP_ID,BussinessPartnerMaster.PAY_MONTH,
    BussinessPartnerMaster.PAY_DAY
    FROM BussinessPartnerMaster
    LEFT OUTER JOIN SalesOrder
    ON BussinessPartnerMaster.BP_ID=SalesOrder.CUSTOMER
    WHERE BussinessPartnerMaster.BILL_TYPE=@BILL_TYPE
    AND BussinessPartnerMaster.CLOSING_DAY=@CLOSING_DAY
    and BussinessPartnerMaster.BP_ID='167301'
    GROUP BY BussinessPartnerMaster.BP_ID,SalesOrder.[SECTION],
    BussinessPartnerMaster.BILL_BP_ID,BussinessPartnerMaster.PAY_MONTH,
    BussinessPartnerMaster.PAY_DAY
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式