Date Range as Parameter

Hi ,
         I have a column with date range in the format 07/21/2014-07/21/2014,
        07/16/2014-07/16/2014
       07/22/2014-07/22/2014
there will be thousands of records like this.
In ssrs I need to pass a pramater with date range =07/16/2014-07/22/2014 then it should display all the records between those dates. I not getting the logic here how to write it.  it is pulling all the dates it is not filtering the dates right now.
Can anybody help me on this issue..
BALUSUSRIHARSHA

It will be much easier if you have two columns holding the range and you pass two parameters to find out the overlapping ranges.
select c1, ..., cn
from T
where @sdt <= dt2 and @edt >= dt1; -- considering the range (dt1, dt2)
or just the exact range:
select c1, ..., cn
from T
where dt1 = @sdt and dt2 = @edt; -- considering the range (dt1, dt2)
Since you store the range in one column of character data type then you need to split the value in two, the start and end points of the range, and do the same with the parameter but this will be easier to change the report to send two parameters instead
one.
Search in this forum or Transact-SQL forum for a function to split a string. Here is a good reference:
Arrays and Lists in SQL Server
http://www.sommarskog.se/arrays-in-sql.html
Once you have created the function, it is a matter of using the APPLY operator, pivot the range and use same predicate as in my first query.
Here is an example but I would encorage you to change the model.
SET NOCOUNT ON;
USE tempdb;
GO
--Itzik's VATN
CREATE FUNCTION dbo.GetNums(@n AS BIGINT) RETURNS TABLE
AS
RETURN
WITH
L0 AS(SELECT 1 AS c UNION ALL SELECT 1),
L1 AS(SELECT 1 AS c FROM L0 AS A CROSS JOIN L0 AS B),
L2 AS(SELECT 1 AS c FROM L1 AS A CROSS JOIN L1 AS B),
L3 AS(SELECT 1 AS c FROM L2 AS A CROSS JOIN L2 AS B),
L4 AS(SELECT 1 AS c FROM L3 AS A CROSS JOIN L3 AS B),
L5 AS(SELECT 1 AS c FROM L4 AS A CROSS JOIN L4 AS B),
Nums AS(SELECT ROW_NUMBER() OVER(ORDER BY (SELECT NULL)) AS n FROM L5)
SELECT TOP (@n) n FROM Nums ORDER BY n;
GO
--Erland's split_me
CREATE FUNCTION dbo.inline_split_me(@param nvarchar(MAX))
RETURNS TABLE AS
RETURN(
SELECT
ROW_NUMBER() OVER(ORDER BY n) AS rn,
LTRIM(rtrim(convert(nvarchar(4000),
substring(@param, n,
charindex(N'-' COLLATE Slovenian_BIN2,
@param + convert(nvarchar(MAX), N'-'),
n) - n)
))) AS Value
FROM dbo.GetNums(LEN(@param))
WHERE substring(convert(nvarchar(MAX), N'-') + @param, n, 1) = N'-' COLLATE Slovenian_BIN2
GO
DECLARE @r varchar(21) = '07/16/2014-07/22/2014';
DECLARE @T TABLE (dt_range varchar(21));
INSERT INTO @T (dt_range)
VALUES
('07/21/2014-07/21/2014'),
('07/16/2014-07/16/2014'),
('07/22/2014-07/22/2014'),
('07/23/2014-07/25/2014');
SELECT
T.dt_range,
R.sdt,
R.edt,
W.p_sdt,
W.p_edt
FROM
@T AS T
CROSS APPLY
SELECT
CAST([1] AS date) AS sdt,
CAST([2] AS date) AS edt
FROM
dbo.inline_split_me(T.dt_range) AS A
PIVOT
MAX(Value)
FOR rn IN ([1], [2])
) AS P
) AS R
CROSS JOIN
SELECT
CAST([1] AS date) AS p_sdt,
CAST([2] AS date) AS p_edt
FROM
dbo.inline_split_me(@r) AS A
PIVOT
MAX(Value)
FOR rn IN ([1], [2])
) AS P
) AS W
WHERE
R.sdt <= W.p_edt
AND R.edt >= W.p_sdt;
GO
DROP FUNCTION dbo.inline_split_me, dbo.GetNums;
GO
Notice that the last row inserted is not part of the result set because it falls outside of the parameter date range.
AMB
Some guidelines for posting questions...

Similar Messages

  • Powershell date range positional parameter error

    I am trying to export emails sent to a particular email address in a specific date range.  I can run the command and it works fine without the date range, but when I try to include it it errors out.  Any help appreciated.
    Working command without date range:
    Get-Mailbox -ResultSize Unlimited | Search-Mailbox -SearchQuery “To:’[email protected]’” -TargetMailbox "SearchResults" -TargetFolder Export
    And repeat it using “From” instead of “To”
    When I try to add a date range though like this:
    Get-Mailbox -ResultSize Unlimited | Search-Mailbox -SearchQuery “To:’[email protected]’” -ContentFilter {(Received -gt '08/15/2014') -and (Received -lt '02/18/2015')} -TargetMailbox "SearchResults" -TargetFolder Export
    I get the below error listing:
    A positional parameter cannot be found that accepts argument '(Received -gt '08/15/2014') -and (Received -lt '02/18/201
    5')'.
        + CategoryInfo          : InvalidArgument: (:) [Search-Mailbox], ParameterBindingException
        + FullyQualifiedErrorId : PositionalParameterNotFound,Search-Mailbox
    Invoke-Command : Cannot write input as there are no more running pipelines
    At C:\Users\exservice\AppData\Roaming\Microsoft\Exchange\RemotePowerShell\kc-exchange.us.org\kc-exchange.us.org.p
    sm1:43760 char:29
    +             $scriptCmd = { & <<<<  $script:InvokeCommand `
        + CategoryInfo          : InvalidOperation: (:) [Invoke-Command], PSInvalidOperationException
        + FullyQualifiedErrorId : NoMoreInputWrite,Microsoft.PowerShell.Commands.InvokeCommandCommand

    Get-Mailbox -ResultSize Unlimited |
    Search-Mailbox -SearchQuery "Received:> $('2014-08-15') AND Received:< $('2015-02-18') AND To:'[email protected]'" -TargetMailbox "SearchResults" -TargetFolder Export

  • Dynamic Date Value for Date Range Parameter - Scheduling in BI

    Hi,
    I am New to BO Enterprise XI R3. I want to schedule the Crystal report which takes Date Range as parameter. Is any option available to calculate From Date automatically based on Current Date based on the range required?
    Currently, Parameter option accepts parameters and enterprise process the report for configured parameters. In this case, report always prints only for configured date range eventhough report generated after one month. I am expecting report has to print data for date range (eg. 1 weeks, 4 days, or any range) based on system current date.
    Thanks in Advance,
    Venkateswaran.P

    I'm am in the same situation.  I need to be able to have the date parameter dynamically change based on the current day's date when I schedule a report.  However, because this parameter comes from a Stored Procedure from the database, it cannot be modified in the Report Designer (as far as I know).  I've tried to set a default for it to use "currentdate" but it doesn't seem to take.  Anyone know if this can be accomplished in the scheduler?
    Thanks
    -Tom

  • Loop Through Date Range

    Hi guys,
    I have date range as parameter like 01/JAN/2009 TO 16/JAN/2009 now i want to loop through this date range and want to get date like
    01/JAN/2009,02/JAN/2009.....16/JAN/2009.how can i achive this ?
    Thanks
    Ron

    Hi,
    What do you mean by loop through?
    SQL> with dates as (select to_date('01/JAN/2009', 'dd/mm/yyyy') start_date
                         ,to_date('16/JAN/2009', 'dd/mm/yyyy') end_date from dual)
    select start_date + level - 1 from dates connect by level <= end_date - start_date + 1
    START_DATE
    01/01/2009
    02/01/2009
    03/01/2009
    04/01/2009
    05/01/2009
    06/01/2009
    07/01/2009
    08/01/2009
    09/01/2009
    10/01/2009
    11/01/2009
    12/01/2009
    13/01/2009
    14/01/2009
    15/01/2009
    16/01/2009
    16 rows selected.Regards
    Peter

  • How would you send a date-range parameter to a SQL sproc?

    Team,
    MY ENVIRONMENT
    SQL 2005, Crystal Reports for Visual Studio 2005
    MY PROBLEM
    I am authoring both a sproc and a report, so I have full control over the design. I am a SQL expert and also a Crystal 8.5 expert.
    I have done the Sproc-Report connection dozens of times.
    Please consider along with me the sequence of creating a report based on a parameterized stored procedure.
    My sproc header is shown here:
    CREATE Procedure dbo.usp_DocumentActivityReport(
         @Department NVARCHAR(50)      
       , @DateRange  NVARCHAR(50)
    ) AS
    SELECT Col1, Col2, Col3 FROM #TEMP
    MY THOUGHT PROCESS
    @DEPARTMENT is a string. That's easy.
    @DATERANGE is a DATE RANGE and I don't know how to get Crystal Reports to prompt for a date range, so I used a String parameter knowing I can parse a specially formatted string, and knowing that I can use a formula to compute the string.
    Step 1. Create the blank report, the {?Department} parameter, the {?CreationDateRange} report parameter, and the {@DateRangeText} conversion formula that converts {?CreationDateRange} to the specially formatted string.
    Step 2. Test the stored procedure.
    Tests pass; It returns data when I run it with values, with zero-length string values, and with NULL values.
    Step 3. Tie the report to the stored procedure.
    Adding the sproc directly creates two hard-wired, undeletable parameters, and returns data columns. That's no good because the user must supply the specially formatted string for the date range. So, I try using Add Command instead, with this syntax:
    {call "EXP_TEST"."dbo"."usp_CorroDocumentActivityReport" (N'{?Department}', N'{@DateRangeText}')}
    This code is accepted, but Add Command did not create any undeletable parameters at all. I guess that's OK.
    But the worst part is that it does not show any output columns with data either! AAARGH!
    Please assist with showing me the proper order to do these steps.
    BTW, here's the VB Syntax formula for {@DateRangeText}:
    Dim min As String
    dim max as String
    if HasLowerBound ({?CreationDateRange}) then
      min = ToText(Minimum({?CreationDateRange}),"MM/dd/yyyy")
    else
      max = ""
    end if
    if HasUpperBound ({?CreationDateRange}) then
      max = ToText(Maximum({?CreationDateRange}),"MM/dd/yyyy")
    else
      max = ""
    end if
    if IncludesLowerBound ({?CreationDateRange}) then
      min = "[" & min
    else
       if HasLowerBound ({?CreationDateRange}) then min = "(" & min
    end if
    if IncludesUpperBound ({?CreationDateRange}) then
        max = max & "]"
    else
       if HasUpperBound ({?CreationDateRange}) then max = max & ")"
    end if
    'formula = min & "..." & max
    formula = "(1/1/2009...3/1/2009)"
    sorry ... cross-posted per Amit

    Ludek,
    It sounds like you and The specified item was not found. think along the same lines! I have cross-posted for both of you now!
    Please see Simple Sproc Parameters question
    ~ Shaun

  • Regarding Date Range parameter

    hello,
    in purchase order, i want to pass date range parameter. For eg .
    I want to fetch data from 21/11/2011 to 25/11/2011
    how to pass parameter for this?? or do i need to create any formula??
    if yes then how/???????
    awaiting for soonest reply.

    hi,
    you need to do this in the Formula workshop.
    this formula {OPOR.DocDate} = {?DateRange}
    {OPOR.DocDate} - this is the PO DocDate
    {?DateRange} - this is what you have done in step #4 in my 1st post. in this example "DateRange" is the name of my Parameter.
    Quote from you post
    {OPOR.DocDate} = {?25/11/2011 to 30/11/2011} In this way should i write a formula??????
    change this {?25/11/2011 to 30/11/2011} to the name of your Parameter. refer to step #4.
    regards
    Fidel

  • Pass a date Range from VB to a parameter

    Hello,
    I'm thinking this is an easy question, but ...
    In a Visual Studio 2008 VB program, I'm allowing the user to pick a starting and ending date from DateTimePickers. (works fiine).
    In a CR 2008 report, I have a paramter defined as "pDateRange",  Type = date, Allow Range Values = Yes.
    In the Record Selection, I use a formula of {tblData.INSTALLDT} in {?Date_Range}.
    When I run the report, I can enter the date ranges in via the Enter Values prompt screen, and it works file,
    All I need to know is - how do I pass the dates the user selected in the VB program to the pDateRange parameter?
    Thanks very much,
    Carl

    Thanks Ludek for the reply.
    Unfortunately, I canu2019t seem to puzzle this out.  None of the examples seem to work.  This is an example, along with their comments.
    I get the error "The parameter field current values cannot contain range values because the ValueRangeKind property is set to discrete." on the last line.
    I could REALLY use some help getting past this issue.
           Dim myReportDocument As New CRS_Tab_Prod_Org_Cnt_Params2
            Dim crParameterFieldDefinitions As ParameterFieldDefinitions
            Dim crParameterFieldDefinition As ParameterFieldDefinition
            Dim crParameterValues As ParameterValues
            Dim crParameterRangeValue As ParameterRangeValue
            crParameterFieldDefinitions = myReportDocument.DataDefinition.ParameterFields
            'Access the individual subreport parameter field "Date_Range"
            crParameterFieldDefinition = crParameterFieldDefinitions.Item("Date_Range")
            'Cast the variable to hold the values to pass to the Report before execution
            crParameterValues = crParameterFieldDefinition.CurrentValues
            'Cast the variable to hold the range value for the parameter
            crParameterRangeValue = New ParameterRangeValue()
            'Set the Date range and include the upper and lower bounds. Use the Cdate function as insurance
            'to ensure that the value passed is cast to the appropriate data type
            With crParameterRangeValue
                .EndValue = CDate("1/1/1997")
                .LowerBoundType = RangeBoundType.BoundInclusive
                .StartValue = CDate("12/20/1997")
                .UpperBoundType = RangeBoundType.BoundInclusive
            End With
            'Apply the Date range to the values to be passed to the Report
            crParameterValues.Add(crParameterRangeValue)
            'Pass the parameter values back to the report
            crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)
    Thanks for your help,
    Carl

  • Date Range parameter

    Hello Everyone,
    I want to create a parameter for date range (From , thru) where the user can put the dates he want to to get the information of the project.
    Pls suggest me.
    Suhana

    Thanks Sathish and Abdul,
    But I forgot to mention one thing.
    I have a subrepor with in this report and I want the date parameter to display so that the user can select the dates and get the information in the subreport.
    For this i think i will have to create a parameter in the main report and then link the subreport.
    But my only concern is where to write which formula. In the record selection of main report or the record selection of subreport.
    Thanks a lot
    Edited by: Suhana01 on Apr 26, 2009 10:38 PM

  • Date Range Parameter's Restriction

    Could you someone please tell me how BO restricts date range parameter when the users tries to run a query?  Often times, users simultaneously try to get several years of data dumped into a single query.  Some users even forget to enforce the date range, which causes the query to try to get the data from the beginning of time. 
    How do we as a BO developer create some sort of date range restriction so that it can prevent users from overloading a query?  If the users want to get several years of data, he/she has to run a query in batches instead of doing it all at once.
    I hope there is a way that we can create a custom informational error message for each report to prevent users from trying to query too many months or years of data.  Some reports may hit small and well-indexed tables that allow large date range queries.  But, some reports query against large and poorly indexed tables, which can potentially cause adverse effect on performance without date range restriction. 
    Any thoughts or advices on how to implement such things (if possible).  I am also afraid that the answer will be "currently not doable".  If so, any ideas if the next version of BO will allow such functionality, or if it is at least in the plan at all?  Thank you so much for your insight and sharing.  Have a great day!

    Dear Amr,
    Thanks so much for your quick reply!  The field I want to create a restriction on is called RESULT_DT_TM.  When I saw the "where" section of the field, I just don't see how I can apply my START_DT_TM and END_DT_TM parameters on this field so that START_DT_TM and END_DT_TM cannot be more than 365 days apart.  If my query does not use parameters called START_DT_TM and END_DT_TM, this "where" section will not be valid? 
    I don't think the solution has to be on the field itself but rather on the parameter START_DT_TM and END_DT_TM.  What I want is that as long as START_DT_TM and END_DT_TM are more than 365 days apart, it does not matter what field these parameters are running against. The screen would then display something saying "your date range parameters for this report must be within 365 days.  Please revise your date range on query".
    Sorry, I am PL/SQL report programmer, and not familiar with what BO can do.  So, is there anyway that can make my dream come true?  Thanks a bunch again, Amr.

  • Date range parameter in heading

    Post Author: hstevens
    CA Forum: Formula
    Given that I've successfully set up a parameter to prompt for a date range, can I now somehow use that in a heading?  Is there someway to extract the dates from that? Or do I have have to set up two parameters - one for the beginning and one for the end date?
    Thanks.

    Post Author: Jean Antoine
    CA Forum: Formula
    To see all values entered, you would need to read and display every element in the array (multivalue).  Something like this:
    StringVar MVpos;
    NumberVar nMaxLen := UBound(multivalue parameter); // sets the upper limits for the values the user entered
    FOR i:=1 to nMaxLen Do
    If i=1 Then
          MVpos := multivalue parameter&#91;i&#93;
    Else
          MVpos := MVPos ', ' multivalue parameter&#91;i&#93;;
    Here, multivalue parameter represents the parameter you've created.  You can place this formula in your header and see every entery entered.
    Best of luck!

  • Pass date range parameter  to SQL stored procedure.

    Hi,
    I'd like to pass a date range parameter from Crystal Reports to a sql stored procedure. Does anyone know if this is possible?
    I've had no problem passing standard datetime (single value) paramaters to and from but am struggling with getting a range value parameter to work.
    Environment: Crystal Reports 10/XI and SQL 2000 MSDE version or SQL 2005 Express Edition.
    Any help would be appreciated.

    C5112736 wrote:>
    > And then these 2 formulas 'Formula # 1' and 'Formula # 2' can be used to pass on to the stored procedure.
    Can someone please demonstrate exactly how to use formula results as date parameters to a SQL stored procedure?  Keep in mind, there are two parameters to the stored procedure.
    I have gleaned this much: Use Add Command and insert the procedure with
    EXEC ServerName.dbo.usp_sprocName;1 '{?StringParameter}'
    but if I try to do
    {CALL ServerName.dbo.usp_SprocName({@Formula1},{@Formula2})}
    then it gives the error "No value given for one or more required parameters". 
    Both of the parameters are VARCHAR(50).
    I have finally found this link: [http://msdn.microsoft.com/en-us/library/ms710248(VS.85).aspx|http://msdn.microsoft.com/en-us/library/ms710248(VS.85).aspx]
    This Microsoft site defines the format of the ODBC escape sequences, but I still do not know how to convince Crystal to insert it's parameter results or formula results.
    Pulling what's left of my hair out . . .
    ~ Shaun

  • CR 2008: Setting currrentdate as default begin date in a date range paramet

    I have a Crystal Report with a date range parameter.
    How do I set the Begin Date to be todays date ?
    I am using a Universe as the data source.
    Thanks,

    Hi Rajesh,
    1) Is the prompt a constant value?
        If yes then type "1900/01/01" in the from value as default value. And in the report selection formula should look similar to this :
    DateVar DateParamValue:-
    If   = Date(1900,1,1)  Then
        DateParamValue := CurrentDate
    Else
        DateParamValue := {?DateParam};
        {Table.DateField} = DateParamValue;

  • Using Date Range parameter in Subreport Selection Formula

    I have a subreport which includes this line in the selection formula:
    {Production.Date} = {?Pm-?DateRange}
    {?Pm-?DateRange} appears in the Subreport Links window, so it seems like it should work.
    The DateRange parameter is set by the user in the Main report.
    But the subreport returns no records.
    I tried this:
    In the Main report I created a StartDate and a StopDate field from {?Pm-?DateRange} .
    Then in the subreport selection formula I used these two formula fields like this:
    {Production.Date} >= @StartDate
    and
    {Production.Date} <= @StopDate
    This works!
    So I have found a workaround, but still, I don't understand why the original code {Production.Date} = {?Pm-?DateRange} returns no records.
    Thanks,
    Art

    Hi Art,
    You cannot use a date range parameter directly in the subreport's record selection formula.
    You'll need to create a formula in the Main report like this:
    Minimum(?DateRange) //This gives the start date
    Maximum(?DateRange) //This gives the end date
    Then send these formulas as parameters to subreport for use in the record selection formula.
    I think you've already got this figured out anyway!
    -Abhilash

  • Disbaling No upper/lower bound value in a date range parameter

    Hi folks,
    When i added a new parameter with a date range , i can see two check boxes 'No lower value' and 'No upper value' along with 'include value' checkbox in the parameter dialog.
    Is there any way to disable these check boxes?? If i cannot disable check boxes and when i select no lower value check box some random date value get returns to the query and the SQL query is giving no results and also i cannot set to a default lower and upper date range too.
    Please help me in resolving this.
    Thanks in advance.

    These features are respective to the range component. If you do not need them, I would suggest that you use two date parameters. One date parameter can act as your low date parameter, and can have it's own default date. The other parameter can act as your high date parameter, and can have it's own default value.
    The only change essentially, in the way the report runs, should be some minor changes to formulas, for example instead of having a selection criteria formula that says in {?DateRange}, you would now say >= {?StartDate} and <=
    Edited by: Kyle McAdam on Aug 15, 2008 6:31 PM

  • Creating a Parameter with pre-defined date ranges.

    How can I create a parameter that will allow the user to select a specific date range for a report (i.e. YTD, MTD, WTD...)? Any suggestions? Thanks...
    Matt Johnson

    You can create & define Parameters in SSRS Report and provide possible values (MTD, YTD or WTD) as drop-down options, the user can then select which one to pick and you can write your T-SQL logic to capture this option and take further query action
    on it
    Good Luck! Please Mark This As Answer if it solved your issue. Please Vote This As Helpful if it helps to solve your issue

Maybe you are looking for

  • Unable to download OS X Mavericks -- Is there a CD available?

    My MAC meets all criteria to do the upgrade (Model 2009, Lion 10.7.5). On the first attempt to download, I was able to see the download icon for a short period. Then it disappeared. After several other attempts, I get a short "time" circle, then noth

  • [SOLVED] Changed daemons & wireless stopped working

    So my problem started after I edited rc.conf to change my daemon array and rebooted. I simply removed network from the daemons sections, rebooted, and upon reboot networkmanager showed no wireless connection. So I re-edited my rc.conf file and placed

  • Overlaping request

    Hi Gurus, delete overlapping request process variant has been failed, in display message error is 'Unknown error'. i have solved the issue, but i want know what could be the reason behind this, same time attribute change run was running is there any

  • Any way to Find correct set of Media from Browser within project?

    I've been working on a bunch of projects for a couple of years -yes- and periodically backed up various media elements to other hard disks. Now I have a problem. Since FCP4.5 places media in the last project's selected folders and because of my backu

  • Online videos problem on OSX

    I have a macbook pro retina with osx yosemite. Every time I play a video online in fullscreen mode (with any browser) it has black borders at the top and the bottom. Anyone knows a solution? Thanks. Here's a screenshot of what I get: http://postimg.o