Using in SQL coalesce with Date

Asked

Viewed 619 times

2

I have the following question. In SQL your doing so works.

...and coalesce(tb_cadastro.cod_produto,'') = coalesce(:COD_PRODUTO, coalesce(tb_cadastro.cod_produto,'')) and ...

Where the COD_PRODUTO is an integer, as I would if the field is of the type DATE? I tried that way, but I’m not getting a date.

...and coalesce(cast(tb_cadastro.dt_pallet AS varchar(10)),'') = coalesce(:DT_PALLET, coalesce(cast(tb_cadastro.dt_pallet AS varchar(10)),''))
  • you have already tried using this within select to see what it returns ?

  • But why are you giving one cast to turn the field date in varchar? If you turn to varchar, I think you’d have to do it with everyone, but you’re not turning the field DT_PALLET.

  • Please Tiago, post the solution of the problem as an answer, instead of putting it directly in the question.

1 answer

0

Resolved as follows:

...and cast(coalesce(tb_cadastro.dt_pallet,'')as date) = coalesce(:DT_PALLET, cast(coalesce(tb_cadastro.dt_pallet,'') as date))

Browser other questions tagged

You are not signed in. Login or sign up in order to post.