1
Hello I have the error in the following code
SELECT L.*, C.DESCRICAO AS CATEGORIA , CASE WHEN L.TIPO_LANCAMENTOS = 'C' THEN 0 ELSE 1 END AS ICONE
FROM LANCAMENTOS L JOIN CATEGORIAS C ON(C.CODIGO = L.COD_CATEGORIA)
WHERE strftime('%m', L.DATA) = '10'
AND strftime('%Y', L.DATA) = '2016'
The select works perfectly already I surrounded this query and is correct the problem starts exactly in Where which is of paramount importance this condition for my filter. I believe that with this code was to be bringing all the records of the month 10 and year 2016, but nothing happens. I tried to make this change.
SELECT L.*, C.DESCRICAO AS CATEGORIA , CASE WHEN L.TIPO_LANCAMENTOS = 'C' THEN 0 ELSE 1 END AS ICONE
FROM LANCAMENTOS L JOIN CATEGORIAS C ON(C.CODIGO = L.COD_CATEGORIA)
WHERE strftime('%m', L.DATA = '10')
AND strftime('%Y', L.DATA = '2016')
I changed the position of closing the parentheses, but this way it does not run the filter and ends up bringing all the records of the table every month and every year and that is not what I want. Thanks for your help.
If you mount SQL like this:
SELECT strftime('%m', L.DATA) AS MES, strftime('%Y', L.DATA) AS ANO FROM LANCAMENTOS L JOIN CATEGORIAS C ON(C.CODIGO = L.COD_CATEGORIA)
What will be the return?– Andrey
That way I didn’t try, but I need to bring all the fields in this table, the date would be just to run the filter
– Alison Paulo
Yes, I understood that. But the return of
SQL
will help us see how to fix the filter. You can let us know the result of thisSQL
that I suggested to you?– Andrey
I did what you said it returns NULL in the fields MES and YEAR I believe you are not able to find the values
– Alison Paulo
There’s the problem... the field
L.DATA
is the typeDate
? Maybe you need to convert the field to Date. Do something like this:strftime('%m', datetime(L.DATA, 'unixepoch'))
– Andrey
It’s DATETIME the field so I’m finding it strange wasn’t supposed to happen this mistake.
– Alison Paulo
Let’s go continue this discussion in chat.
– Andrey