lundi 30 novembre 2015

Mysql update if

this is the query i am trying to use.

  SET @id = 289;
    SET @feedId = 5;
    SET @statusid = 2;
    SET @processId = 1;

    SET @feedIdExists = (
     SELECT EXISTS (
       SELECT *
       FROM feed_statuses
       WHERE FeedId = @feedId));

    IF feedIdExists = 1 THEN
     UPDATE `snap`.`feed_statuses` 
      SET
      `ProcessId` = @processId , 
      `StatusId` = @statusId , 
      `ProcessEndDate` = NOW()
      WHERE
      `FeedId` = @feedId;
    ELSE
     INSERT INTO `snap`.`feed_statuses` 
      (`FeedId`, 
      `ProcessId`, 
      `StatusId`, 
      `ProcessStartDate`
      )
      VALUES 
      (@feedId,
      @processId,
      @statusId,
      NOW());
    END IF;

hi guys, there are 3 errors about the if syntax. i didnt understand. why doesnt it work properly?

Aucun commentaire:

Enregistrer un commentaire