That's to less on information.
Please post table design as DDL, some sample data as DML statement and the expected result.
Additional, in T-SQL you can use for an IF statement the CASE/WHEN/ELSE condition.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi there,
How to write the below query in ms sql
If(Num(Month(TempDate))>6,Year(TempDate)&'/'&Year(addmonths(TempDate,12)),Year(Addmonths(TempDate,-12))&'/'&Year(TempDate)) AS FinancialYear
Many Thanks
That's to less on information.
Please post table design as DDL, some sample data as DML statement and the expected result.
Additional, in T-SQL you can use for an IF statement the CASE/WHEN/ELSE condition.
Hi @ASHMITP ,
Please refer below:
create table #temptable
(TempDate date)
insert into #temptable values
('2019-03-01'),
('2020-06-01'),
('2021-08-01')
select iif(MONTH(TempDate)>6,cast(year(TempDate) as char(4))+'/'+cast(year(TempDate)+1 as char(4)),
cast(year(TempDate)-1 as char(4))+'/'+cast(year(TempDate) as char(4))) AS FinancialYear
from #temptable
Output:
FinancialYear
2018/2019
2019/2020
2021/2022
Best regards,
Melissa
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.