Format date in Values for a Range (Gant) Chart SSRS 2008 R2 - sql

I have a date column in which the dates are re-curring every year. I'm only interested in the month really, but I can't just put the month number as the high and low value for the gant chart. Is there any way I can format the column? Any suggestions would be awesome.
The gant chart currently is taking the whole date and is working fine, but like I said it goes out to the next year.

Figured it out. So the DATECOLUMN I had was formated as such:
Example: 2013-01-01 00:00:0.000
In order to put in the GANT(RANGE) CHART in the series property, under values, I formated the Top Value and Low Value as =MONTH(DATECOLUMN) using the expression option.
Then for the Horizontal Axis Properties I set the Interval to 1 and Interval Type to Number. And There you have it Monthly time spans with only the Months 1 - 12 showing.
I must also note that I only had one time recorded. So I just did Top Value as: DATEADD(MM,1,DATECOLUMN) In Order to get the right time span in my dataset Script.

Which date format would u like to display in your chart.
If (month with year) like 'Sep 2013'
use this date format for the same.
SUBSTRING(CONVERT(VARCHAR(11),getutcdate(), 113),4,8)

Related

How to Cast Date to String for Chart with Weekly Groupings in MS Access

I have a simple Access application where I want a chart that shows groupings by weeks from daily records.
I have a query that converts the groups by the week and then displays the week as the first day like this:
WeekBegin: DateAdd("d",-(DatePart("w",[ScoreDate])-1),[ScoreDate])
Thsi gives the Sunday beginning the week correctly. The problem comes when I go to make a chart. The chart Row Source is
SELECT [WeekBegin],Sum([Scores]), (etc...) FROM [query] GROUP BY [WeekBegin];
When I do this the chart treats the bottom axis as a date value and each week is seven days apart making the bars tiny.
I'm sure the date format is the issue because when I make an integer out of the week value it formats how I want:
I can't figure out how to get it to show as a date like "mm/dd" but not treat it as a date and add all those blank days in between. I've tried messing with the axis settings but it doesn't seem to do anything.
Try casting the date as a varchar... use convert to get into whatever display format you want.

Get the month and year now then count the number of rows that are older then 12 months in SQL/Classic ASP

I know this one is pretty easy but I've always had a nightmare when it comes to comparing dates in SQL please can someone help me out with this, thanks.
I need to get the month and year of now then compare it to a date stored in a DB.
Time Format in the DB:
2015-08-17 11:10:14.000
I need to compare the month and year with now and if its > 12 months old I will increment a count. I just need the number of rows where this argument is true.
I assume you have a datetime field.
You can use the DATEDIFF function, which takes the kind of "crossed boundaries", the start date and the end date.
Your boundary is the month because you are only interested in year and month, not days, so you can use the month macro.
Your start time is the value stored in the table's row.
Your end time is now. You can get system time selecting SYSDATETIME function.
So, assuming your table is called mtable and the datetime object is stored in its date field, you simply have to query:
SELECT COUNT(*) FROM mtable where DATEDIFF(month, mtable.date, (SELECT SYSDATETIME())) > 12

When a start date and end date span more than one week, I need to split a row up in 2 or more new rows

I would like to begin by saying I'm quite new to sql.
That said, here is my question/problem:
I have a view that has two date columns, a variable column and a text column (for comments).
I need to be able to split up all rows where the two dates are not in the same week. And I need to be able to split the variable value as well, so that it gets evenly distributed, based on how many days were in each week. The comment must be copied as well, so to be shown in each row.
My dataset looks like this:
DateIn DateOut Amount Comment
2014-11-01 2014-11-08 600 Good
And what I want is this:
DateIn DateOut Amount Comment
2014-11-01 2014-11-07 525 Good
2014-11-08 2014-11-08 75 Good
And if the time period spreads over more weeks, I would need it to split up to equivalent number of rows.
I would be very greatful if somebody could take the time to tell me how to achive my goal, using an sql-query.
As this is my first post on the forum, I apologize for any format errors in my post.
First, you need a weeks table. I mean physical table or view, where exists one row for every week possible. (We have dates table here, +/- 30 years from now - allows easily create weeks view and similar).
Then you need link your data to weeks table with left join; join condition should check date ranges overlap with week date range (probably you have to have both week start and week end fields in your weeks table - makes comparisons easier).
Then you need to divide amounts between weeks. Because you know date range length, week length and overlapping date range length, this should be trivial :)

Pass the monthly value of an SSRS report chart into another report with date from and date to parameters

I have a yearly chart that it broken down into the 12 months Jan - Dec. The report contains various parameters including a yearly dropdown that changes the chart and report.
This all works fine within the first report.
The problem is that I have set up an action on the chart to go to a second report with a monthly breakdown, so my question is how can I pass the monthly value from the first report to the second?
The monthly report has an additional date from and date to parameter, so for the month of January it would need the values: Date From: 01/01/2010 and Date To: 31/01/2010 for example.
Thanks in advance.
Since you have the year and month integer values, you can construct the start and end dates to pass to your other report using expressions.
The start of the month will be:
=DateSerial(Fields!Year.Value, Fields!Month.Value, 1)
Where Year and Month are the integer values from the Chart/Dataset.
The end date is a bit more complicated; since the day part can be 30/31, etc, but we can just add one month to the above expression to get the first of the next month, then go back a day:
=DateAdd(DateInterval.Day
, -1
, DateAdd(DateInterval.Month, 1, DateSerial(Fields!Year.Value, Fields!Month.Value, 1)))
This way your drillthrough report can get its date based parameters and you don't need any changes to your dataset/parent report.

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.