title: Google Spreadsheet Query IF(ISBLANK(), PARSE_ERROR:
body: <p>With this Query I get this result. The idea is i have a date of the product that is sold. When check if the date is between date_start and date_end of the marketing table, if so put that price in the marketingprice.</p>
  
  <p>In some cases there is no end. This mean it's still running and has no end date. We still use them.
  Because there is no end date I want to use the date of today. So if E (date_end) is empty , use the today date if not then use E</p>
  
  <pre><code>=query(Marketing!$B$2:E,
  "select C,D  where  B='" &amp; D2 &amp; "' and 
  D&lt;=date '"&amp;TEXT(E2,"yyyy-MM-dd")&amp;"' and 
  date'"&amp;TEXT(today(),"yyyy-MM-dd")&amp;"'&gt;=date '"&amp;TEXT(E2,"yyyy-MM-dd")&amp;"' ")
  
  +------------+---------------+--------+-----------------+----------+----------------+
  | product_no | product_price | amount | deliver_country |  datum   | marketingprice |
  +------------+---------------+--------+-----------------+----------+----------------+
  |       1001 |           2.8 |      2 | de              | 2-1-2020 |                |
  +------------+---------------+--------+-----------------+----------+----------------+
  +-----+------------+
  | 3.2 | 01-01-2020 |
  | 1.2 | 02-01-2020 |
  +-----+------------+
  </code></pre>
  
  <p>I want to use IF(isblank(E),date'"&amp;TEXT(TODAY(),"yyyy-MM-dd")&amp;"', E)</p>
  
  <p>Then the code will be </p>
  
  <pre><code>=query(Marketing!$B$2:E,
  "select C,D  where  B='" &amp; D2 &amp; "' and 
  D&lt;=date '"&amp;TEXT(E2,"yyyy-MM-dd")&amp;"' and 
  IF(isblank(E),date'"&amp;TEXT(today(),"yyyy-MM-dd")&amp;"',E)&gt;=date '"&amp;TEXT(E2,"yyyy-MM-dd")&amp;"' ")
  </code></pre>
  
  <p>Then I get a error:</p>
  
  <blockquote>
    <p>QUERY: PARSE_ERROR: Encountered "  "IF "" at line 1, column 58.
    Was expecting one of: "(" ... "(" ...</p>
  </blockquote>
  
  <p>Marketing Table</p>
  
  <pre><code>+---------+---------+-------+-------------+------------+
  | channel | country | price | date_start  |  date_end  |
  +---------+---------+-------+-------------+------------+
  | Google  | de      |   3.2 | 01-01-2020  | 01-01-2020 |
  | Google  | de      |   1.2 | 02-01-2020  |            |
  | Amazon  | en      |   5.4 | 01-01-2020  |            |
  +---------+---------+-------+-------------+------------+
  </code></pre>
  
  <p>Output how it should be </p>
  
  <pre><code>+------------+---------------+--------+-----------------+----------+----------------+
  | product_no | product_price | amount | deliver_country |  datum   | marketingprice |
  +------------+---------------+--------+-----------------+----------+----------------+
  |       1001 |           2.8 |      2 | de              | 2-1-2020 |            1.2 |
  |       1002 |           3.8 |      4 | en              | 3-1-2020 |            5.4 |
  |       1001 |           2.8 |      1 | de              | 1-1-2020 |            3.2 |
  +------------+---------------+--------+-----------------+----------+----------------+
  </code></pre>
  
  <p>In mysql I use this code :</p>
  
  <pre><code>b.start_date                &lt;= date(i.system_created)                                           AND   
  coalesce(b.end_date,now())  &gt;= date(i.system_created)
  </code></pre>
  
  <p>Solution i found myself:</p>
  
  <pre><code>=QUERY(Marketing!$B$2:$E;IF(Marketing!E$2:E="";
  "select E where  B ='"&amp;D2&amp;"' and D &lt;=date'"&amp;TEXT(E2;"yyyy-MM-dd")&amp;"' and date'"&amp;TEXT(VANDAAG();"yyyy-MM-dd")&amp;"' &gt;=date'"&amp;TEXT(E2;"yyyy-MM-dd")&amp;"' limit 1";
  "select E where  B ='"&amp;D2&amp;"' and D &lt;=date'"&amp;TEXT(E2;"yyyy-MM-dd")&amp;"' and E &gt;=date'"&amp;TEXT(E2;"yyyy-MM-dd")&amp;"'"
  );0)
  </code></pre>