sql >> Databasteknik >  >> RDS >> Mysql

MySQL lagrad procedur med IF/THEN/ELSE

Prova den här konstruktionen

WHILE (@RowCnt <= @MaxRows)
BEGIN
    SELECT @currentReadSeq:=ReadSeq, @currentReadStrength:=ReadStrength, @currentReadDateTime:=ReadDateTime, @currentReaderID:=ReaderID FROM tblTempRead WHERE rownum = @RowCnt;

    IF (((@lastReadSeq + 10) > @currentReadSeq) AND (@lastReaderId = @currentReaderId))
        BEGIN
        SET @lastReadSeq = @currentReadSeq, @lastReadStrength = @currentReadStrength, @lastReadDateTime = @currentReadDateTime, @lastReaderID = @currentReaderID;
        END
    ELSE
        BEGIN
        INSERT INTO tblreaddataresults (SiteID, ReadDateTimeStart, ReadDateTimeEnd,ReadSeqStart, ReadSeqEnd, ReaderID, DirectSeconds) VALUES ('1002',@saveReadDateTime, @lastReadDateTime, @saveReadSeq, @lastReadSeq, @lastReaderID,timestampdiff(SECOND,@saveReadDateTime,@lastReadDateTime));
        SET @saveReadSeq = @currentReadSeq, @saveReadStrength = @currentReadStrength, @saveReadDateTime = @currentReadDateTime, @saveReaderID = @currentReaderID;
        SET @lastReadSeq = @saveReadSeq, @lastReadStrength = @saveReadStrength,@lastReadDateTime = @saveReadDateTime, @lastReaderID = @saveReaderID;
        END
    SET @RowCnt = @RowCnt+1;
END



  1. Nästa närmaste datum och tid i MySQL

  2. Linq to Entities Group By (OUTTER APPLY) oracle 11.2.0.3.0 stöder inte applicera

  3. Exportera enorm databas från Amazon RDS till lokal mysql

  4. Sammanfoga fält med rader med samma ID i MySQL