Declare @BeforeValue int;
set @BeforeValue =DATEDIFF(DAY,DATEADD(yy, DATEDIFF(yy, 0, GETDATE()), 0),getdate());
BEGIN
SELECT * FROM SYSSETTING S1
INNER JOIN
SYSSETTINGVALUE OffsetDaysBefore
ON(S1.PKey=OffsetDaysBefore.SysSettingPKey)
INNER JOIN
EtpSalesOrg ON(EtpSalesOrg.id=OffsetDaysBefore.SalesOrg)
WHERE
S1.Status<>'d' AND OffsetDaysBefore.Status<>'d' AND
EtpSalesOrg.status<>'d';
UPDATE OffsetDaysBefore SET OffsetDaysBefore.value=@BeforeValue
FROM SYSSETTINGVALUE OffsetDaysBefore
INNER JOIN SYSSETTING S1
ON( S1.PKey=OffsetDaysBefore.SysSettingPKey )
WHERE S1.pkey='00100000007p3e4a' and S1.id='TestBefore';
END;
--------------------------------------------------------
DECLARE @a INT=(
select DATEDIFF(DAY,DATEADD(yy, DATEDIFF(yy, 0, GETDATE()), 0),getdate()));
Create table #temp(id int);
INSERT INTO #temp values(1),(5),(6);
select * from #temp;
--
id
--
1
5
6
UPdate #temp set id=@a where id=5;
select * from #temp
--
id
--
1
313
6