Hi,
I am looking at changes in data for two months and would like to see the changes include old records(in last month but not in this month), same records (in both months) and new records (in this month and not in last month).
I am doing calculations on these so if it returns a blank or null it would be good if it returned 0.
My current query picks up the mutual and new records but not the old records (i.e. the ones that have dropped off). Is there a way I can set my where the function to pick up the old records as well?
where reportDate in (@currentmonthend) OR (in(@previous monthEnd) AND NOT in (@currentmonth end).
My query looks like this:
declare @currentMonthend as date
declare @previousMonthEnd as date set @currentMonthend = '12/31/2022'
set @previousMonthEnd = eomonth(@currentMonthend, -1) select
cha.ID059Code
,cha.portfolio
,cha.securityDescription
,cha.accruedInterest,
(select chr.accruedInterest from tblPortCharacteristics chr
where chr.reportDate = @previousMonthEnd
and chr.ID059Code = cha.ID059Code
and chr.portfolio = cha.portfolio
and chr.securityDescription = cha.securityDescription) AS "Previous month Accrued"
,cha.accruedInterest -
(select chr.accruedInterest from tblPortCharacteristics chr
where chr.reportDate = @previousMonthEnd
and chr.ID059Code = cha.ID059Code
and chr.portfolio = cha.portfolio
and chr.securityDescription = cha.securityDescription) AS "change in accrued"
from dbo.tblPortCharacteristics cha
where cha.reportDate in(@currentMonthend) OR (in(@previousMonthEnd) AND not (@currentMonthend))