2
Hello, everybody. I am running the query below and is showing the error: "Operand type Clash: int is incompatible with date".
My intention in performing this query is to validate whether the field VENCIMENTO_ORIGINAL is a valid date, and if so, validate whether the day of this date is equal to the day of the DTINICIO field. Does anyone know what could be going wrong? Follow the query below:
UPDATE A
SET DIVERGENCIA_DE_VENCIMENTO = 'NÃO'
FROM TMP_LAYOUT_DIRETRIZES A
WHERE ISDATE(A.VENCIMENTO_ORIGINAL) = 1
AND CASE WHEN ISDATE(A.VENCIMENTO_ORIGINAL) = 0 THEN CAST(NULL AS DATE)
ELSE DAY(CONVERT(DATE,VENCIMENTO_ORIGINAL,103))
END = DAY(CONVERT(DATE,DTINICIO,103))
EDIT: The following is an example of the data in the TMP_LAYOUT_DIRETRIZES table:
vencimento_original dtinicio
2018-09-20 20/09/2014
2018-09-20 20/09/2015
2018-09-20 20/12/2015
2018-09-20 20/06/2016
2018-09-20 20/08/2016
2018-09-20 20/03/2017
2018-09-20 20/09/2017
2018-09-28 20/04/2018
2018-09-20 20/07/2018
2018-09-20 20/07/2018
CAST(NULL AS DATE)
? That doesn’t make any sense. Put it straightNULL
in that case, without theCAST
– Sorack
When I do this, there appears another error: Conversion failed when Converting date and/or time from Character string.
– Paulo Felicio
Paul, in this case, neither CAST nor CONVERT will work. NULL is different from 'NULL', and in this case any conversion p/ date on sql server you will need to have a date that is possible to convert.
– Adjair Costa
Put an example of the data you have in this table
TMP_LAYOUT_DIRETRIZES
to see how your field isVENCIMENTO_ORIGINAL
andDTINICIO
– Sorack
Your dates don’t follow a pattern. There are some that are
YYYY-MM-DD
and others areDD/MM/YYYY
– Sorack
I put SET DATEFORMAT DMY at the beginning of the query, and still could not convert. Both fields are varchar.
– Paulo Felicio