Hi smile,
You need to use DATEADD function.
Refer below sample query.
SQL
DECLARE @tblProtocol AS TABLE (Days_After INT,Protocol VARCHAR(50))
INSERT INTO @tblProtocol VALUES(10,'Utirus Check')
DECLARE @tblCalving AS TABLE (ID INT,CalvingDate DATE,Gender VARCHAR(1))
INSERT INTO @tblCalving VALUES(1,'2023-07-17','M')
INSERT INTO @tblCalving VALUES(2,'2023-07-18','F')
INSERT INTO @tblCalving VALUES(3,'2023-07-19','M')
SELECT ID,CalvingDate,Gender,
DATEADD(DAY,(SELECT Days_After FROM @tblProtocol),CalvingDate) [Days_Count]
FROM @tblCalving
Output
ID |
CalvingDate |
Gender |
Days_Count |
1 |
2023-07-17 |
M |
2023-07-27 |
2 |
2023-07-18 |
F |
2023-07-28 |
3 |
2023-07-19 |
M |
2023-07-29 |