0
I have a screen where I have a list of a company’s payment titles, and I need to do a dynamic search from the issue date of the title. The idea is that when the user enters the date in a search field, this data will be passed dynamically via AJAX
to a file where there will be the query SQL
.
My doubt, is how I will assemble my clause WHERE
?.
Ex: WHERE data_emissao ILIKE '%2015-01-01%'
Can someone help me?
Will use like in a date column? explains better this, between would not be more appropriate?
– rray
When the user enters the date, e.g.: 10/23/2015, all titles released that day will be returned in a list. Basically that’s it, I thought to use the between but this function works with two dates an initial and the other final, and in case here I only have a date. Eai?
– Bruno Duarte
And you have a problem with ?
WHERE data_emissao = '2015-01-01'
, if you want you can pass the date asdd/mm/yyyy
direct at the bank, see here– rray
Yes, because in addition to the search by date has the social reason, cnpj and title number, both are treated with string and the date of issue is of type date. With this returns the following error:
ERRO: sintaxe de entrada é inválida para tipo date: "2015"
SQL state: 22007
– Bruno Duarte
The doubt I have is what kind you set the column to be wanting to use
ILIKE
. She’s sweeping or Timestamp?– Guilherme Lautert
The user informs a complete date or only a piece, month, year etc? Puts the code you have so far, can give a lightened.
– rray
Follows the code:
SELECT titulo.id_titulo, titulo.numero_empresa, participante.razao_social, 
 participante.cpf_cnpj, titulo.data_emissao, titulo.valor,
 titulo.autorizado
FROM titulo
INNER JOIN participante ON( titulo.id_participante = participante.id_participante )
WHERE titulo.numero_empresa ILIKE '%2015%'
OR participante.razao_social ILIKE '%2015%'
OR participante.cpf_cnpj ILIKE '%2015%'
ORDER BY id_titulo DESC
LIMIT 10 OFFSET 0;
– Bruno Duarte