I have a following Data
tblCalving
ID Tag C_Date
1 101 2023-08-10
2 105 2023-08-15
3 107 2023-08-21
tblProtocol
ID Days Pro_Name
1 0 PU + BU
2 5 I.U Check
3 10 Utrus Examination
Required output:
In tblCalving data is added on 2023-08-10 and 2023-08-15. Now we want to fectch data based on current date. So, this added data will be mapped with tblProtocol for adding days. In tblProtocol Days value is 0 and 5 and 10. Today is 2023-08-15, Hence 0 days will be added in 2023-08-15 and 5 days will be added in 2023-08-10. Now output will be like that following table.
ID Tag C_Date Days New Date
1 101 2023-08-10 5 2023-08-15
2 105 2023-08-15 0 2023-08-15
I wtote the following query.
SELECT CalvID,C_Date,DATEADD(DAY,(SELECT D_After FROM tblProtocol where PID='2'),C_Date) as [Date] FROM tblCalving
where [NewDate]=CONVERT(varchar(10), GETDATE(), 23)
It is showing me following error
Msg 207, Level 16, State 1, Line 2
Invalid column name 'NewDate'.
how to get solution plz?