SQL Reporting Services 2005 - How to get the current date as ReportParameter

I have some working reports that need to be deployed to SSRS. Another setting that I want to add is to automatically select FromDate as it is today - 1 month, and ToDate - today.

In particular, I want to replace the fragment below with a part that will fulfill the above requirements:

 <ReportParameter Name="FromDate">
  <DataType>String</DataType>
  <DefaultValue>
    <Values>
      <Value>[Date].&amp;[2008-09-26T00:00:00]</Value>
    </Values>
  </DefaultValue>
  <Prompt>From Date</Prompt>
  <ValidValues>
    <DataSetReference>
      <DataSetName>FromDate2</DataSetName>
      <ValueField>ParameterValue</ValueField>
      <LabelField>ParameterCaption</LabelField>
    </DataSetReference>
  </ValidValues>
</ReportParameter>
<ReportParameter Name="ToDate">
  <DataType>String</DataType>
  <Prompt>To Date</Prompt>
  <ValidValues>
    <DataSetReference>
      <DataSetName>ToDate</DataSetName>
      <ValueField>ParameterValue</ValueField>
      <LabelField>ParameterCaption</LabelField>
    </DataSetReference>
  </ValidValues>
</ReportParameter>

Thanks in advance.

+3
source share
2 answers

Replace hard-coded

[Date].&amp;[2008-09-26T00:00:00]

to the formula

=DateAdd("m", -1, Now)

For "ToDate," just pass in a formula that returns the current date

=Now

Now the result looks something like this.

<ReportParameters>
    <ReportParameter Name="FromDate">
        <DataType>DateTime</DataType>
        <DefaultValue>
        <Values>
            <Value>=DateAdd("m", -1, Now)</Value>
        </Values>
        </DefaultValue>
        <AllowBlank>true</AllowBlank>
        <Prompt>FromDate</Prompt>
    </ReportParameter>
    <ReportParameter Name="ToDate">
        <DataType>DateTime</DataType>
        <DefaultValue>
        <Values>
            <Value>=Now</Value>
        </Values>
        </DefaultValue>
        <AllowBlank>true</AllowBlank>
        <Prompt>ToDate</Prompt>
    </ReportParameter>
</ReportParameters>

[]
, <ReportParameters> ToDate; . RDL . .

  • FromDate:
    alt text

  • ToDate:
    alt text

+8

TSQL, .net:

=Now()

=DATEADD("m", -1, now())
+1

Source: https://habr.com/ru/post/1704510/


All Articles