How to create month year drop down parameter in SSRS 2005? - sql-server-2005

In SSRS 2005, I need to provide a drop down to the user with month year labels for the last two months.
For e.g. Jan 2010, Feb 2010, ... , Jan 2011, .... Dec 2011
I need this dynamically for the last two years (say).
Additionally, as user select one of the label, I need to pass the last date of the selected month-year combination to the query parameter.
Please help!
Sijoy

Assuming you are reporting from a SQL datasource, create a new dataset with a query to return the last date of each month within the required range (ie. the last two months) and the month-year description of each month - the details of the query will vary depending on the SQL database (MySQL, SQLServer, Oracle, etc). Populate the parameter from this new dataset, and set the value to be the date field and the label to be the description field.

Related

Querying data from quite old IBM iseries AS400 DB2 (date format issue)

I am quite a newbie in querying data from databases and now I am currently having an issue with date format in very old (I don't know exact version) IBM iSeries AS400 DB2 database. My problem is that the date is stored in this DB in three separate columns as whole number (column day + column month + column year) and I need to connect to this DB via ODBC in Excel and filter just a few rows according to desired date span (e.g. from 1st December 2019 until 31st December 2019). In this case I don't want to use PowerQuery to do all the modifications, because the complete table has millions of rows. I want to specify the filter criteria within SQL string so the PowerQuery doesn't have to load all the rows...
My approach was following:
I've created 6 parameter cells in Excel sheet where I simply defined Date From (e.g. cell 1 = '01', cell 2 = '12' and cell 3 = '2019') and Date To (same logic for parameter cells 4, 5 and 6). Then I mentioned these parameter cells in SQL string where I defined:
(Day >= Parameter cell 1, Month >= Parameter cell 2, Year >= Parameter cell 3)
and
(Day <= Parameter cell 4 etc.)
This worked quite good for me, but only when I liked to export just a few hundreds of lines within the same year. But now I am facing to an issue when I like to export data from 1st December 2019 to 31st January 2020. In this case my "logic" doesn't work, because Month From is '12' and Month To is '01'.
I've tried another approach with concat SQL function to create text column like '2019-12-01' and then convert this column to datetime format (with cast to varchar8 first), but it seems that this approach doesn't work for me, because everytime I get an error which says: "Global variable DATETIME not found".
Before I post you some of my code, could I ask you for an advise, if you can think of a better solution or approach for my issue?
Many thanks and have a great day :-)
A simple solution would be
select * from table where year * 100 + month between 201912 and 202001

SSRS Generic Drop Down Month Parameter

I am using Visual Studio 2012 and SQL Server 2012. I'm trying to create a simple drop down parameter to show generic month/year over a given timeframe, lets say last 5 or 6 years (for example... Sept 2016, Oct 2016, etc).
Edit: My goal with this is that I have a StartDate field for a record and all records that fall within a certain Month, I want to capture with the parameter.
I have already been using a parameter for Start Date and End Date using Date/Time field when creating my parameter to get a range. I no longer wish to use that because my end user wants it simply by month/year.
This is the code I have which shows only the Month of the Start Date right now. How do I amend this code to show Month and Year?
SELECT DISTINCT DATENAME(month,A.[STRT_DTTM]) AS [Month]
FROM Work as A
WHERE A.[STRT_DTTM] IS NOT NULL
ORDER BY DATENAME(month,A.[STRT_DTTM])
Additionally once code is amended, how would I go about this to sort month by normal calendar flow (aka Jan, Feb, Mar, Apr...?)
Try SSRS, which you probably have -
Then have a look at this - Basically you choose the 'Date' type for the drop down parameter: https://technet.microsoft.com/en-us/library/aa337401(v=sql.105).aspx
SELECT DISTINCT DATENAME(month,A.[STRT_DTTM]) AS [Month]
FROM Work as A
WHERE A.[STRT_DTTM] IS NOT NULL
ORDER BY DATENAME(month,A.[STRT_DTTM])

extracting common data of current months and last two monnth sql

I have a table with more than 20000 rows, In one of column i have month from jan 2014 to Dec 2014, and in another column i have a loan number. Most of the loan Numbers are reapeting every months,now i need to get only the loan Number which are apperead in all three monthy consecutively. For eg if i am getting data for current months i also wanted get data which are common in two months before the current months. The database that i m using is Access DB. Any adivice will be more than a help, Thanks in Advance.
SELECT Loans.LoanID, Sum(IIf([period]=[month],1,0)) AS CM, Sum(IIf([period]=[month]-1,1,0)) AS [m-1], Sum(IIf([period]=[month]-2,1,0)) AS [m-2]
FROM Loans
GROUP BY Loans.LoanID
HAVING (((Sum(IIf([period]=[month],1,0)))>1) AND ((Sum(IIf([period]=[month]-1,1,0)))>1) AND ((Sum(IIf([period]=[month]-2,1,0)))>1));
I used month as an integer, and didn't make any adjustment for months 1 and 2 to loop back and look at prior year - you should be able to modify this based on the actual format you are using for the month.

How to get month within a range vb2010

I just don't know how to go about this.
I designed a program that uses MS Access as its database. I have a field for month and year (the field data type is text) where user can register details. The program will register the month and year the user have chosen e.g month= September, year=2011.
My problem now is how to chose a range of data to view by the user using the month and year as a criteria e.g the User may want to view data range from (September 2011 to July 2013).
I couldn't figure out even how to try. Help will be highly appreciated.
Perhaps you could change your application logic to store the month and year as their respective numbers rather than text and change the field data types to numeric.
You could then construct a DateTime object from them, for example September would be 9 and you could use code like the following:
var startDate = new DateTime(year, month, 1); // get year and month as integers from database, uses the first as the date
var endDate = new DateTime(year, month, 10); // change the date but keeps the month and year the same
var endDate2 = startDate.AddMonths(1); // adds 1 month to the date
Alternatively, you could try using a calendar control to allow the user to select two dates instead of building it from a number of fields. Depending on what you are using this could be achieved a number of ways, for example in ASP.Net or WPF you could use two calendar controls and just use their SelectedDate properties as your range.
A range is from a startpoint until an end point. For the startpoint you can add automatically the first of Month. For the endpoint is it more complicated because there is no fix endpoint. What you can do is following:
Write an array that contains for each month the days (e.g. 30 or 31). Except for Febrauary there is a fix pattern.
for Febrauary use the selected year to check is the year a leap year or not. If not add 28, else add 29.
After that create the date string for your SQL:
Startdate 1.9.2011. Do for the entdate the same.
After that, I think you can use the keyword between in your SQL query.
You can assume that everything is entered on the first day of each month. I would pull the information using a query to the database.
select * from [tablename] where DateSerial([colYear], [colMonth], 1) between DateSerial([fromYear], [fromMonth], 1) and DateSerial([toYear], [toMonth], 1)
In this question are some ways to do this:
First. Filter the dates in a range assuming that you use a date like '07-12-2012'
i.e. September 2011 to July 2013
Where DateColumn > '09-01-2011' and DateColumn < '07-31-2013'
OR
Specify a Date and a Year
Where month(DateColumn)='1' and year(DateColumn)='2016'
Note:
There are many ways to do this.
You can Manipulate your statement depending on your desired output.

MDX - Get the last 3 members of the selected member

I am pretty new with MDX so please bear with me.
I am designing an analytical chart with PerformancePoint in which the bottom(X) axis will display a date range. The displayed date range will depend on the selected value of the date filter, which is based on the DATE dimension with this hierarchy: Year>Quarter>Month.
Let's say the user selects 2010 from the date filter. We want the query to return the last 4 years prior to the 2010 (2007,2008,2009,2010). If Q1-10 is selected, we want the last 4 quarters including Q1-10. If a month is selected (Sept 2010), we want the last 4 months (June 2010, July 2010, Aug 2010, Sept 2010).
I appreciate any kind of help.
Use the LastPeriods function:
LastPeriods(4, <<UniqueName>>)