SQL Server Variable Timeperiod with a dash

rhfm7lfc  于 2022-12-22  发布在  其他
关注(0)|答案(1)|浏览(147)

I need to create a variables called Reporting_Period, which I retrieve from the date variable: Return Closing Date. Reporting_Period needs to look like 2019 - 2020 or 2020 - 2021 etc
I am having problems incorporating that dash and I tried +' - '+
The error message I am getting is:
Operand type clash: date is incompatible with int
What do I need to do?
The code I am trying is as below:

,((YEAR ([Return Closing Date])) +' - '+ (DATEADD(YEAR, -1,([Return Closing Date])))) AS [Reporting_Period]
bzzcjhmw

bzzcjhmw1#

Excellent @JohnCappelletti, is worked:

,CONCAT(YEAR ([Return Closing Date]), '-' ,(YEAR(DATEADD(YEAR, -1,([Return Closing Date]))))) AS [Reporting_Period]

相关问题