Altering timestamp

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #16
    I'm pretty sure this should throw an error as
    "you cannot update a table and select from the same table in a subquery" (MySql Manual)
    Code:
    ewise_slice.slice_timestamp
    What query browser are you using, Is error reporting / logging switched on?
    Also are you sure the subquery returns only one value

    Comment

    • dbrewerton
      New Member
      • Nov 2009
      • 115

      #17
      I modified my query to the way you've suggested. I ran it through a query analyzer and when it runs even with static variables, it gives me a null result. I am using the one that comes with MySQL Administrator.

      Comment

      • code green
        Recognized Expert Top Contributor
        • Mar 2007
        • 1726

        #18
        How have you modified the query? Because the syntax was actually illegal

        Comment

        • dbrewerton
          New Member
          • Nov 2009
          • 115

          #19
          Yes, I re-wrote the SP like this so I'm only impacting the very last record. It currently reads as follows:

          ############### ####
          delimiter ;

          DROP PROCEDURE IF EXISTS `fixmytimes`;

          DELIMITER $$
          CREATE PROCEDURE `fixmytimes`(IN RealTime text, IN countit INT)
          BEGIN

          declare time1 TIMESTAMP;
          declare Timevar TIMESTAMP;
          declare firstrec INT default 1;
          declare mycount INT default 1;
          declare fixedtime TIMESTAMP;
          declare maxslice INT;

          SELECT MAX(slice_id) as maxslice, slice_timestamp AS time1 from ewise_slice;
          SELECT timestampdiff(M INUTE,time1,Rea lTime) INTO Timevar;
          SELECT maxslice - countit INTO firstrec;

          while mycount < countit DO

          SELECT date_Add(time1, INTERVAL Timevar MINUTE) AS fixedtime;
          UPDATE ewise_slice set slice_timestamp = fixedtime where slice_id = firstrec;

          set mycount = mycount+1;
          set firstrec = firstrec+1;
          END WHILE;

          END
          $$

          ############### #####

          Comment

          • code green
            Recognized Expert Top Contributor
            • Mar 2007
            • 1726

            #20
            I cannot explain the NULL result.
            All I can suggest is test each query seperately to find the failing query.
            Then breakdown that query into simpler steps using one value at a time.
            This is called debugging

            Comment

            Working...