Hi,
I am trying to build a YTD query for my reporting solution the following query in DB2, and the following query is from SSMS. Can anyone help me writing this qury in DB2? I will appreciate any help and guidance.
For example if the report runs on April 7th, 2016, so it will take the data from Jan 1st, 2016 to March 31st, 2016.
Moreover, when the [highlight #FCE94F]report run on Jan 7th, 2017[/highlight], so it will [highlight #FCE94F]take the data from Jan 1st, 2016 to Dec 31st, 2016[/highlight].
When it will [highlight #FCE94F]run on Feb, 7th 2017[/highlight], so it will take the data from [highlight #FCE94F]Jan 1st, 2017 to Jan 31st, 2017[/highlight].
--First of Every Month
where date >= case when month(getdate())=1 then convert(varchar(4),year(getdate())-1)+ '/01/01'
else convert(varchar(4),year(getdate()))+ '/01/01'end
--end of every month
where date < case when month(getdate())=1 then convert(varchar(4),year(getdate())-1)+ '/01/01'
else convert(varchar(4),year(getdate()))+ '/' +convert(varchar(2),month(getdate()))+'/01' end
Thanks and Regards,
Fka0006
I am trying to build a YTD query for my reporting solution the following query in DB2, and the following query is from SSMS. Can anyone help me writing this qury in DB2? I will appreciate any help and guidance.
For example if the report runs on April 7th, 2016, so it will take the data from Jan 1st, 2016 to March 31st, 2016.
Moreover, when the [highlight #FCE94F]report run on Jan 7th, 2017[/highlight], so it will [highlight #FCE94F]take the data from Jan 1st, 2016 to Dec 31st, 2016[/highlight].
When it will [highlight #FCE94F]run on Feb, 7th 2017[/highlight], so it will take the data from [highlight #FCE94F]Jan 1st, 2017 to Jan 31st, 2017[/highlight].
--First of Every Month
where date >= case when month(getdate())=1 then convert(varchar(4),year(getdate())-1)+ '/01/01'
else convert(varchar(4),year(getdate()))+ '/01/01'end
--end of every month
where date < case when month(getdate())=1 then convert(varchar(4),year(getdate())-1)+ '/01/01'
else convert(varchar(4),year(getdate()))+ '/' +convert(varchar(2),month(getdate()))+'/01' end
Thanks and Regards,
Fka0006