I have dimTime table below:
TheYear Fiscalyear TheMonthName TheMonth
2022 2022 - 2023 November 11
2022 2022 - 2023 October 10
2022 2022 - 2023 September 9
2023 2022 - 2023 February 2
2023 2022 - 2023 January 1
How to implement the MonthName and Year as SSRS parameter and have this in the main dataset? Like below:
Select Month-Year: January-2023
Dataset: Select
from Table
where date = selected MonthYear from the parameter
This will also goes to same report but the selection is Fiscal year:
*Select Fiscal Year: 2022-2023
Dataset: Select
from Table
where date = selected FiscalYear from the parameter
Im trying to convert it to date but dont know where to start.
Related
I have a DateTime field that I want to summarise and format to YYYY mmm, then use as an SSRS parameter to filter my query.
Q1. When I use the format option the dates I get back are sorted as text e.g.
2022 Apr
2022 Feb
2022 Jan
2022 Mar
Q2. How do I sort as per the calendar e.g.
2022 Jan
2022 Feb
2022 Mar
2022 Apr
Q3. How do I use the values of this parameter in my WHERE clause to filter my dates? So if someone chooses "2022 Mar" I only get data where the DateTime field contains March 2022.
try_convert(date,...) will assume the 1st of the month if no day is given
Example
Declare #YourTable Table ([SomeCol] varchar(50))
Insert Into #YourTable Values
('2022 Apr')
,('2022 Feb')
,('2022 Jan')
,('2022 Mar')
Select *
From #YourTable
Order By try_convert(Date,SomeCol)
Results
SomeCol
2022 Jan
2022 Feb
2022 Mar
2022 Apr
You can sort it out by just using 'ORDER BY'
EX:
CREATE TABLE #TEMP_DATES
(Month_Year Date)
INSERT INTO #TEMP_DATES
SELECT
'2022 APR',
'2022 FEB',
'2022 JAN'
SELECT * FROM #TEMP_DATES
ORDER BY Month_Year
I have a data set like this
Year
Records
2020
1
2020
2
2021
3
2021
4
2022
5
2022
6
I want show all the history records up to the selected year in Slicer:
2020
2021
2022
For example, if I select 2020, it should show:
Year
Records
2020
1
2020
2
And if I select 2021, it should show:
Year
Records
2020
1
2020
2
2021
3
2021
4
If I select 2022, it should show:
Year
Records
2020
1
2020
2
2021
3
2021
4
2022
5
2022
6
I am very appreciated if you have some ideas for me.
Regards
Use a "less than or equal to" Numeric Range Slicer on the Year
I have a table that contains some DateTime values stored as text, and I want to loop through them and get the DateTime object for each one.
Here are some examples of the data that I need to convert it.
26 Tuesday November 2019 - 09:00 AM
25 Monday November 2019 - 11:20 AM
06 Friday December 2019 - 10:00 AM
22 Sunday December 2019 - 01:05 PM
22 Sunday December 2019 - 04:00 PM
22 Sunday December 2019 - 02:30 PM
23 Monday December 2019 - 11:00 AM
I tried to use the SQL built-in functions (e.g. cast, convert,...) but didn't work.
Remove the name of the weekday and the hyphen and it should work:
WITH cte
AS
(
SELECT DATENAME(weekday,datefromparts(2020,1,dow.dow)) as WeekDay
FROM (values (1),(2),(3),(4),(5),(6),(7) ) dow(dow)
)
SELECT TRY_CAST(REPLACE(REPLACE(t.dateInTxt,'-',''),cte.WeekDay,'') as datetime),t.dateInTxt
FROM mytable t
JOIN cte
ON t.dateInTxt LIKE '%'+cte.WeekDay +'%'
How can I get The months names from Current month to April only using SQL
Ex:-if the current month is July then I want the month names from July to April.
Current month should be the running month.
Any function or something like that....(I need to get the data from Db for those months)
This should work:
WITH Dates AS
(
SELECT GETDATE() D
UNION ALL
SELECT DATEADD(MONTH,1,D) FROM Dates WHERE DATEPART(MONTH,D)!=4
)
SELECT DATENAME(MONTH,D) [Month Name] FROM Dates
Result
Month Name
------------------------------
September
October
November
December
January
February
March
April
I have a table that contains datefield and product. I want the below pivot query to show the month total, quarter total and year total.
Year Month A B C
-----------------
2014 Jan
2014 Feb
2014 Mar
2014 Q1
2014 Apr
2014 May
2014 Jun
2014 Q2
2014 Jul
2014 Aug
2014 Sep
2014 Q3
2014 Oct
2014 Nov
2014 Dec
2014 Q4
2014 Total
2015 Jan
2015 Feb
2015 Mar
2015 Q1
Refer this Simple-Way-To-Use-Pivot-In-SQL-Query from CodeProject, the code given in the example is more similar to your requirement.
I think this is what you are talking about.
SELECT 'Count' AS Month,
[Jan], [Feb]
FROM
(SELECT year, month
FROM Product) AS SourceTable
PIVOT
(
count(year)
FOR Month IN ([Jan],[Feb])
) AS PivotTable;
Out Put
Month Jan Feb
Count 2 2
This is what you are expecting.
Count Month quarter Year
Count 24 8 2
But We cannot categorise month, year unless they are designated as months, quarter etc. If there is any flag which denotes that Jan and Feb are months then we can categorise them based on Months.