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
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
Hi @ASHMITP-0361,
Could you please validate all the answers so far and provide any update?
Please remember to accept the answers if they helped. Your action would be helpful to other users who encounter the same issue and read this thread.
Thank you for understanding!
Best regards,
Melissa
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-0361,
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.
14 people are following this question.
Year and Month aggregation in same Pivot table in SQL Server
SQL Server Query for Searching by word in a string with word breakers
How to show first row group by part id and compliance type based on priorities of Document type?
Query to list all the databases that have a specific user
T-sql query to find the biggest table in a database with a clustered index