title: mysql - MySQL Prepared stamement bind same value multiple times using one variable
body: <p>I have a query that is being run multiple times so i tried to use Prepared statements. But i want to know if there is a way in which i can bind same value/variable to multiple parameter.</p>
  
  <p>Here is the query in question</p>
  
  <pre><code>PREPARE stmt_pn FROM ' SELECT  `date`, `product_id`, `price` FROM `prd`.`pn_ceramic` WHERE `date` IN ( DATE_ADD("2014-08-05", INTERVAL ? DAY) , DATE_ADD("2014-08-16", INTERVAL ? DAY) , DATE_ADD("2014-08-23", INTERVAL ? DAY)  ) ';
  
  SET @dn = '1';
  
  EXECUTE stmt_pn USING @dn;
  </code></pre>
  
  <p>This gives me </p>
  
  <pre><code>ERROR 1210 (HY000): Incorrect arguments to EXECUTE
  </code></pre>
  
  <p>Here is a sample data set</p>
  
  <pre><code>+---------------------+------------+-------+
  | date                | product_id | price |
  +---------------------+------------+-------+
  | 2014-08-05 00:00:00 |  1.27      | 2.10  |
  | 2014-08-06 00:00:00 |  1.47      | 3.00  |
  | 2014-08-07 00:00:00 |  1.57      | 2.39  |
  | 2014-08-16 00:00:00 |  1.87      | 4.17  |
  | 2014-08-17 00:00:00 |  1.37      | 6.06  |
  | 2014-08-18 00:00:00 |  1.37      | 2.20  |
  | 2014-08-23 00:00:00 |  1.67      | 4.85  |
  | 2014-08-24 00:00:00 |  1.47      | 5.34  |
  +---------------------+------------+-------+
  </code></pre>
  
  <p>From this data set the query should return </p>
  
  <pre><code>+---------------------+------------+-------+
  | date                | product_id | price |
  +---------------------+------------+-------+
  | 2014-08-06 00:00:00 |  1.47      | 3.00  |
  | 2014-08-17 00:00:00 |  1.37      | 6.06  |
  | 2014-08-24 00:00:00 |  1.47      | 5.34  |
  +---------------------+------------+-------+
  </code></pre>
  
  <p>As i'm trying to bind multiple parameter using the same value, but i wonder what is the fastest and cleanest way to achieve this. Because in my case the number of dates in the Where in clause can exceed 100 and for every case the interval will be the same. So i don't want to create like 100 variables for each of the 100 parameters which will all have the same values . Also performance is crucial in my case , and adding another loop to create 100 variables is something i want to avoid.  </p>