SQL Services Reporting Services Cascading Parameter - ssrs-2008

I have 2 parameters in my report to select a date range:
StartDate & EndDate
I want to hide the StartDate and allow users to just select the EndDate which should then dynamically change the start date to 1 year before the EndDate.
I need this to happen every time a user changes the EndDate changes.
I'm pretty sure I have to use cascading parameters, but I don't know how.
Any suggestions?

Yes, cascading parameters are the trick if you want to do this at the report level. (You could also handle this pretty effectively at the query level.)
First arrange the parameters in your report in order of dependence: EndDate should be be listed above StartDate. Use the up and down arrows to rearrange the parameters.
Set the StartDate parameter to be "Internal" and set the default value appropriately. Select "Specify values" and create a value of =DATEADD( DateInterval.Year, -1, Parameters!EndDate.Value )
Now you can use both #EndDate and #StartDate in your query without initializing them and they will be passed the SSRS value.

Related

The group options for a date, time or date-time condition field must be a date group

I'm using VS2017 and trying to convert my reports from Delphi to Asp.Net, but the problem with some until this point that My users can change their sort from the GUI and I need to dynamically adjust the sort in code to match their selection.
To do this I use the following code:
ReportDocument.DataDefinition.Groups[i].ConditionField = ReportDocument.Database.Tables[CrystalReportDatasource].Fields[cField];
However if cField is aDateField and the original is a StringField group I receive the following exception:
The group options for a date, time or date-time condition field must be a date
group options object crystal reports" when I try and excute the above
statement.
Any idea how to fix that?
When you group on a date, Crystal needs to know what type of date grouping you wish to apply (e.g. Every Day, week, or Month...).
You need to take care of that aspect in code or simply create a String formula to convert the date column to a string and Group on that formula instead of on the raw date column.

SSRS Preset or Custom Date Selection on Report

I currently have a report with the ability to select a start and end date. I was curious if you could make have both preset and the option for a custom selection
Selection:
Current Week, or
Previous Week, or
Custom Date Range.
Thanks,
Take a look at cascading parameters.
The link above seems to focus more on getting your cascading parameter values from a query, but you probably don't want that for a date - as far as I am aware, setting Available Values for a date parameter limits you to a dropdown list of dates, instead of the calendar which is generally easier to use. It is still a good background on how cascading parameters work though.
To do this with expressions for the default start/end date, you would basically want the first parameter to be a choice between "Current Week", "Previous Week", and "Custom Date Range". You would display those labels to the user, but the values can be whatever you want - for my test I just used 1, 2, and 3.
Then, you would set up 2 more parameters, one for the start date and one for the end date. Make sure the data type is Date. You will want to set up default values for these based on the value of the first parameter. I would do this with an expression such as the expression below for the start date. You also may need to modify this a bit depending on how you define the week - is the "Current Week" just the previous 7 days, or is it the latest Monday through today, or something else, etc.
=Switch(
Parameters!FirstParam.Value = 1, DateAdd("d", -7, Today()),
Parameters!FirstParam.Value = 2, DateAdd("d", -14, Today())
)
In this case, you don't even need to account for the 3rd option, because if the user wants a custom date range then you do not want the start and end date to fill in with any default values. You would need a similar expression for the default end date as well.
Since you want the user to be able to enter a custom range as well if they were to select the third option, you do not want to fill in the Available Values for the start/end date parameters, as the user would then not be able to select any date (at least as far as I am aware - if there is a workaround to that, I would love to see it, as that would be something I would like to use myself).
A possible downside to this approach is that if the user begins by selecting Current Week and then changes their mind to Previous Week, the start/end dates will not change to the Previous Week. You can read more about why this happens here, but essentially: since the values that are already filled in after selecting Current Week are still valid (they are dates, which is the only criteria for those parameters since no available values are set up), they will not refresh after changing the selection. The fix for this is to define the Available Values, but as mentioned above, this will then stop the user from entering a custom date range.

How to create default date set on a calendar in Tableau

I have one vertica query in my tableau,
select * from mytable where Date(sometimestamp) between
start_date and end_date
As you can see data varies as per change in date range.
My issue is to set start_date as default to current_date - 90 and end_date as current_date.
There is not issue in making end_date as current_date but no idea about how to set start_date as current_date-90 in tableau.
I tried making calculated fields etc but none helps.
Could you please guide me on how to do that.
Note - Both, start_date and end_date should be calendar component not dropdowns or slider.
You can accomplish this by adding a filter to your data source -- note that you won't be able to control this filter from the dashboard (if that's what you want to do, you'll need to create a calculated field and let the users interact with it), rather, this is a datasource level filter.
Go to the data source and click "Add" under the filters text in the top right, then click "Add"
Click the "Relative dates"
Then, select Relative Dates, Months, Last 3 (Or select Days and enter 90 under the "Last" radio button) and press OK.
You said you have the end date handled, but you can create another data source filter to handle the end date if you want.

CRM 2011 Custom page and SQL TimeZone Issue

I have a custom aspx application that directly queries the CRM database base tables such as ActivityPointer to get the data such as due date, created on etc. The custom aspx page need to filter data based on certain date range such as for today, last 7 days etc. It does so by executing custom sproc stored in CRM database. However I am facing challenge with the user timezone issue getting the correct data.
DECLARE #StartDate DATETIME;
DECLARE #EndDate DATETIME;
DECLARE #NoOfDay INT= 7 -- passed as param
SET #StartDate = DATEADD(day, DATEDIFF(day, #NoOfDays-1, GETDATE()), 0)
SET #EndDate = DATEADD(day, DATEDIFF(day, - 1, GETDATE()), 0)
This will always return the startdate and enddate based on the machine timezone where the sql instance is running. What would be the correct approach to set the start date/end date so it also considers user timezone settings? I don't think I can use CRM specific functions such as dbo.fn_UTCToLocalTime() etc because my custom aspx will be using a different account to access/execute the sproc.
Aside from maybe a direct SQL call being a little overkill for this, I'd just change the SP to accept a start and end date, and send in the UTC version of the dates you want to constrain the results to
You really shouldn't be hitting the tables directly. CRM provides a whole bunch of views that add additional fields (and cater for security roles etc).
If you look at the Views, you should find FilteredActivityPointer. This view will then have the date-time formatted and time-zone adjusted based on your current user.
The Filtered* views should be used for all reports

Comparing two time columns in ASP.NET

I'm rather new to ASP.NET and SQL, so I'm having a tough time trying to figure out how to compare two time columns. I have a timestamped column and then a Now() column in an .mdb database. I need to have a gridview display records that are "Greater than or equal to 3 hours" from the timestamp. Any idea how I can accomplish this?
The Transact-SQL timestamp data type is a binary data type with no time-related values.
So to answer your question: Is there a way to get DateTime value from timestamp type column?
The answer is: No
You need another column of datetime2 type and use > operator to for comparison. You might want to set default value of getutcdate() to set it when each row is inserted.
UPDATE:
Since the column is of datetime type and not timestamp type (there is a type in SQL Server called timestamp, hence the confusion) you can just do
WHERE [TimeCalled] <= DATEADD(hour, -3, GETDATE())
Make sure your server is running in the same timezone as your code. It may be safer to store all dates in UTC. In that case use GETUTCDATE instead on GETDATE
Timestamps are generally used to track changes to records, and are updated every time the record is changed. If you want to store a specific value you should use a datetime field.
If you're using a DateTime Column and you want the result in TSQL try
DATEDIFF(Hour, 'Your DateTime Column here', 'pass Now() here' )
try to execute this example in TSQL:
select DATEDIFF(Hour, '2012-11-10 00:00:59.900', '2012-11-10 05:01:00.100')