mysql和vb6-stored过程

时间:2017-06-08 09:34:42

标签: mysql stored-procedures vb6

您好,我在下面有以下代码......

DELIMITER $$

USE `gateshms`$$

DROP PROCEDURE IF EXISTS `SP_Rank_by_Company`$$

CREATE DEFINER=`gates`@`%` PROCEDURE `SP_Rank_by_Company`(PETSA VARCHAR(50),ins VARCHAR(200))
BEGIN
    IF ins = "DELETE" THEN

        DELETE FROM tblrevrankreport WHERE xdate = PETSA;

    ELSEIF ins = "INSERT" THEN

        INSERT INTO tblrevrankreport (ndate, xDate, tid, transid, rmno, rmcat, rmcatdesc, rmtariff,
            marketdesc, cindate, coutdate, 
            mulrate,
            revamt,
            othamt,
            Company) 
        SELECT a.xDate, a.xDate, b.id, a.guestno, a.roomno, b.RoomCat, b.roomcat, b.Room_Tariff,
            b.Market, b.CInDate, b.coutdate, 
            b.MultipleRate,
            IF(c.ratecode=1,(a.amount-(a.AMT_VAT+a.AMT_SC+a.AMT_LT)),''),
            IF(c.ratecode<>1,(a.amount-(a.AMT_VAT+a.AMT_SC+a.AMT_LT)),''),b.Company
            FROM  tbltransactionpostingdumy a 
            LEFT JOIN tblcustomerinfo b ON a.MaintransNo = b.transactionID
            LEFT JOIN tblreftransaction c ON a.trcode = c.xcode
            WHERE a.xDate = PETSA AND c.xcat = 'ROOM CHARGE';

    ELSEIF ins = "UPDATE_NNN1" THEN

        UPDATE  tblrevrankreport tr INNER JOIN tblcustomerinfohistory tc
            ON tr.xDate = tc.xDate
                AND tr.`transid` = tc.`TransactionID` 
                AND tr.`xDate` = PETSA
                AND tr.COutDate > tr.xdate 
                AND (tr.rmcat <> 'PQ' OR tr.rmcat <> 'Walkin')
        SET tr.nyts = 1,
            tr.NoOfAdult = tc.NoOfAdult,
            tr.NoOfChild = tc.NoOfChild;

    ELSEIF ins = "UPDATE_NNN2" THEN

        UPDATE tblrevrankreport
        SET   
            nyts = '0', 
            NoOfAdult = '0', 
            NoOfChild = '0'
        WHERE xdate = PETSA
            AND coutdate<=xdate;

    ELSEIF ins = "UPDATE_ROOMTARIFFDESC" THEN

        UPDATE tblrevrankreport,tblroomrate
        SET tblrevrankreport.`rmtariffdesc` = tblroomrate.`rateDesc`
        WHERE tblrevrankreport.rmtariff = tblroomrate.`room_type` 
        AND tblrevrankreport.xdate = PETSA;

    ELSEIF ins = "UPDATE_ROOMDESC" THEN

        UPDATE tblrevrankreport,tblroom
        SET tblrevrankreport.`rmdesc` = tblroom.`roomdesc`
        WHERE tblrevrankreport.`rmno` = tblroom.`Room_No`
        AND tblrevrankreport.xdate = PETSA;

    ELSEIF ins = "UPDATE_MARKETCODE" THEN

        UPDATE tblrevrankreport,tblcmarket
        SET tblrevrankreport.marketCode = tblcmarket.`xCode`
        WHERE tblcmarket.`xDesc` = tblrevrankreport.`marketdesc`
        AND tblrevrankreport.xdate = PETSA;
    END IF;
    END$$

DELIMITER ;

对于某个报告,因为我在程序运行期间无法添加进度条(它会导致应用程序无响应)我添加了一个名为&#34; ins&#34;只是为了查询每个查询的整个过程,然后在它之间添加一个ui操作,请参阅下面的代码:

Public Sub processRevRank(ByVal MyDate1 As String, ByVal MyDate2 As String)

    '-- LATEST CODE AS OF JUNE 08, 2017
    Dim RSC As ADODB.Recordset
    Dim sDate As String
    sDate = Format(MyDate1, "yyyy-mm-dd")

    Dim xDays As Integer
    If MyDate1 = "" And MyDate2 <> "" Then
        MyDate2 = MyDate1
        xDays = DateDiff("d", MyDate2, MyDate2)
    ElseIf MyDate1 <> "" And MyDate2 = "" Then
        MyDate1 = MyDate2
        xDays = DateDiff("d", MyDate1, MyDate1)
    ElseIf MyDate1 <> "" And MyDate2 <> "" Then
        xDays = DateDiff("d", MyDate1, MyDate2)
    Else
        Unload frmLoadingReports
        Exit Sub
    End If

    Dim xWidth As Integer
    If xDays <> 0 Then
        xWidth = 886 / xDays
    Else
        xWidth = 886
    End If

    Do Until CDate(sDate) > CDate(MyDate2)
        frmLoadingReports.lblTitle.Caption = "PROCESSING ( Rank by Company : " & sDate & " )"

        frmLoadingReports.lblLoadingTitleBack.Caption = "Deleting Records"
        frmLoadingReports.lblLoadingTitleFront.Caption = "Deleting Records"
        frmLoadingReports.picLoading.Width = frmLoadingReports.picLoading.Width + xWidth
        DoEvents

        Set RSC = Nothing
        Set RSC = OpenRS("CALL SP_Rank_by_Company('" & sDate & "','DELETE')")

        frmLoadingReports.lblLoadingTitleBack.Caption = "Inserting Records"
        frmLoadingReports.lblLoadingTitleFront.Caption = "Inserting Records"
        frmLoadingReports.picLoading.Width = frmLoadingReports.picLoading.Width + xWidth
        DoEvents

        Set RSC = Nothing
        Set RSC = OpenRS("CALL SP_Rank_by_Company('" & sDate & "','INSERT')")

        frmLoadingReports.lblLoadingTitleBack.Caption = "Updating Records"
        frmLoadingReports.lblLoadingTitleFront.Caption = "Updating Records"
        frmLoadingReports.picLoading.Width = frmLoadingReports.picLoading.Width + xWidth
        DoEvents

        Set RSC = Nothing
        Set RSC = OpenRS("CALL SP_Rank_by_Company('" & sDate & "','UPDATE_NNN1')")

        frmLoadingReports.lblLoadingTitleBack.Caption = "Updating Room Tariff Description"
        frmLoadingReports.lblLoadingTitleFront.Caption = "Updating Room Tariff Description"
        frmLoadingReports.picLoading.Width = frmLoadingReports.picLoading.Width + xWidth
        DoEvents

        Set RSC = Nothing
        Set RSC = OpenRS("CALL SP_Rank_by_Company('" & sDate & "','UPDATE_ROOMTARIFFDESC')")

        frmLoadingReports.lblLoadingTitleBack.Caption = "Updating Room Description"
        frmLoadingReports.lblLoadingTitleFront.Caption = "Updating Room Description"
        frmLoadingReports.picLoading.Width = frmLoadingReports.picLoading.Width + xWidth
        DoEvents

        Set RSC = Nothing
        Set RSC = OpenRS("CALL SP_Rank_by_Company('" & sDate & "','UPDATE_ROOMDESC')")

        frmLoadingReports.lblLoadingTitleBack.Caption = "Updating Marketcode"
        frmLoadingReports.lblLoadingTitleFront.Caption = "Updating Marketcode"
        frmLoadingReports.picLoading.Width = frmLoadingReports.picLoading.Width + xWidth
        DoEvents

        Set RSC = Nothing
        Set RSC = OpenRS("CALL SP_Rank_by_Company('" & sDate & "','UPDATE_MARKETCODE')")

        sDate = DateAdd("d", 1, MyDate1)
        sDate = Format(sDate, "yyyy-mm-dd")
    Loop

    frmLoadingReports.lblLoadingTitleBack.Caption = "Done"
    frmLoadingReports.lblLoadingTitleFront.Caption = "Done"
    frmLoadingReports.picLoading.Width = 5320
    DoEvents

    'timer for closing
    frmLoadingReports.Timer4.Enabled = True

    Exit Sub
End Sub

我仍然不满意,因为没有响应仍然发生,我正在考虑在查询中删除UPDATE部分,因为ui在事务和日期中挂起了该部分。

我的问题是...... 如何在其上创建带有SELECT table1的存储过程,然后使用所选记录UPDATE table2并将其循环直到满足某个条件?任何循环选择和更新的简单sql存储过程?

谢谢!

1 个答案:

答案 0 :(得分:0)

不是试图在UI中修复此问题(或作为第一步),您是否满意自己已经调整数据库以尽可能高效地运行这些查询?