title: Mysql Set Variable ve Stored Procedure
body: <p>I have a question about mysql stored procedure and variables;</p>
  
  <p>Table Name : es_adwords
  Fields : id  # image_source # image_link # computer_id # is_all_pc # image_state # banner_size</p>
  
  <p>I want to create stored procedure that should search  computer_id = {pc_number} and image_state = 0.</p>
  
  <p>If not, stored procedure should return to be equal to is_all_pc = 1.</p>
  
  <pre><code>DELIMITER $$
  DROP PROCEDURE IF EXISTS `GetAdwordsBanner` $$
  DELIMITER $$
  CREATE PROCEDURE `GetAdwordsBanner`(IN compid INT)
  BEGIN
  SET @result_id := 0;
  
  SELECT @result_id := id FROM es_adwords WHERE image_state = 1 AND computer_id = compid ORDER BY id DESC LIMIT 0,1;
  
  IF (@result_id != 0) THEN
      SELECT image_source,image_link,banner_size FROM es_adwords WHERE image_state = 1 AND computer_id = compid ORDER BY id DESC LIMIT 0,1;
  ELSE
      SELECT image_source,image_link,banner_size FROM es_adwords WHERE image_state = 1 AND is_all_pc = 1 ORDER BY id DESC LIMIT 0,1;
  END IF;
  
  END $$
  DELIMITER ;
  </code></pre>
  
  <p>Sincerely Yours...</p>