Error reading Like with Timestampdiff

2

Good People Visual Studio can not read the column Days to do a search with like and gives error! I believe he reads the code at once and does not find Dias created with TIMESTAMPDIFF (DAY, Date_date, Date_of_promise).
How could I organize the above code for it to do some research and show the result without giving error?

"SELECT ID, Nome_do_cliente, Data_do_compromisso, Data_de_hoje,
  Data_do_cadastro, Data_de_hoje, TIMESTAMPDIFF(DAY, Data_de_hoje, 
  Data_do_compromisso) AS Dias FROM agenda WHERE CONCAT('Nome_do_cliente', 
 'Data_do_compromisso', 'Data_de_hoje', 'Dias')LIKE '%" + valorpesreb + "%'";

Error message:

  

Error reading data! Unknown Column 'Dias' in Where Clause

    
asked by anonymous 14.07.2016 / 13:05

1 answer

0

You can only use column aliases in GROUP BY , ORDER BY or HAVING .

  

The SQL standard does not allow you to refer to a column alias   in a WHERE clause. This constraint is imposed because when the   WHERE is executed, the value of the column may still not be determined.

     

Source: link

So, to solve your problems we will have to double the line of timestampdiff in where , since we can not use Alias. By doing the following:

SELECT id
      ,nome_do_cliente
      ,data_do_compromisso
      ,data_do_cadastro
      ,data_de_hoje
      ,timestampdiff(DAY, data_de_hoje, data_do_compromisso) dias

  FROM agenda
 WHERE CONCAT(nome_do_cliente
             ,data_do_compromisso
             ,data_de_hoje
             ,timestampdiff(DAY, data_de_hoje, data_do_compromisso)) LIKE
              '%" + valorpesreb + "%';

I ran the test on SQLFIndle .

    
14.07.2016 / 16:02