'sqlserver change date based condition current date
this is my query :
select distinct idArticulo, costoProveedor ,min (fechaRecepcion) as Desde,
max(fechaRecepcion) as Hasta
into #tmp_precios_cambios_historia
from Tbl_NetSuite_Articulos tnsa
group by idArticulo, costoProveedor
select *
from #tmp_precios_cambios_historia
where idArticulo like 'PU_886412/02_1_1'
group by idArticulo, costoProveedor, Desde, Hasta
And I get this :
| idArticulo | costoProveedor | Desde | Hasta |
|---|---|---|---|
| PU_886412/02_1_1 | 537.8000 | 2021-06-03 15:05:00.000 | 2021-06-09 14:32:00.000 |
| PU_886412/02_1_1 | 626.1500 | 2021-06-11 13:47:00.000 | 2021-07-01 13:02:00.000 |
| PU_886412/02_1_1 | 659.6100 | 2021-09-17 15:46:00.000 | 2022-03-15 17:44:00.000 |
I need to replace last date from "Hasta" column (2022-03-15 17:44:00.000). If it's < than getdate() by current date (getdate())...I don´t know if there is some window function ...I tried with conditionals, but I couldn´t solve it...It's an example with one article, but I have more than 1MM articles, so I nned the same for each article...compare las "Hasta" Date vs today and replace it... Could someone help me please? Thanks
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
