简体   繁体   中英

SSRS Conversion from Access Query

We have reports that are currently running from inside a macro on an Access database that we want to convert to SSRS reports.

I want to convert the Access query into a Shared Dataset that these reports can share as there are two parameters I would like to pass into this Shared Dataset, but I am having an issue getting this to work.

SELECT * FROM FROM ReportLog WHERE ClientName = [ClientNameParameter] AND 
DateEntered BETWEEN getstartdatedaily() AND DATE() - 1
ORDER BY DateEntered;

The above query is what I want to put into the Shared Dateset, but for each report, I would pass into the query the Client Name (I do not want the report to prompt the user for this) and getStartDateDaily is a function inside Access that I am not sure how to convert this to something SSRS can use. Below is the code that runs the function, as I am not sure how to convert this to a parameter / function that the SSRS Report can use.

Public Function getStartDateDaily() As Date
    Dim startDate As Date
    Dim endDate As Date
    If Weekday(Date) = 2 Then
        startDate = Date - 3
    Else
        startDate = Date - 1
    End If
    getStartDateDaily = startDate
End Function

Would greatly appreciate any help.

Northwind metaphor example

Use Northwind
Go

Select * from
(

SELECT [OrderID]
      ,[CustomerID]
      ,[EmployeeID]
      ,[OrderDate]
      ,[RequiredDate]
      ,[ShippedDate]
      ,[ShipVia]
      ,[Freight]
      ,[ShipName]
      ,[ShipAddress]
      ,[ShipCity]
      ,[ShipRegion]
      ,[ShipPostalCode]
      ,[ShipCountry]
      ,DATEPART(dw,[OrderDate]) as MyDATEPART
      , StartDateDaily =
      CASE
      WHEN DATEPART(dw,[OrderDate]) = 2 THEN DATEADD(d, -3, CURRENT_TIMESTAMP)--Date - 3
        ELSE DATEADD(d, -1, CURRENT_TIMESTAMP)  -- Date - 1
      END
  FROM [Northwind].[dbo].[Orders]
) as derived1

Where OrderDate between StartDateDaily and  DATEADD(d, - 1, CURRENT_TIMESTAMP)

The above works.

My guess at yours: (hint, temporarily comment out the where clause below to see the computed values (MyDATEPART and StartDateDaily ) of the equation and tweak those if necessary)

Select * from
(

SELECT *
      ,DATEPART(dw,DateEntered) as MyDATEPART
      , StartDateDaily =
      CASE
      WHEN DATEPART(dw,DateEntered) = 2 THEN DATEADD(d, -3, CURRENT_TIMESTAMP) 
        ELSE DATEADD(d, -1, CURRENT_TIMESTAMP)
      END
  FROM ReportLog
) as derived1

Where DateEntered between StartDateDaily and  DATEADD(d, - 1, CURRENT_TIMESTAMP)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM