i have a report in ssrs with odbc data source as the data is stored in oracle database
in the normal scenario while adding some filters in ssrs report they are not working
after searching, i found that i can add these filters in the dataset query as below and this expression worked find
="SELECT * FROM VIEW_NAME " & IIF(IsNothing(Parameters!partynumber.Value),"","WHERE A.PARTY_NUMBER=:partynumber )
but when i tried to add another parameter in this expression nothing returned from the query after using the filters
so please is there any idea can help!!
Since you are already building your query with the Dataset's Expression Builder, why not use it for your Parameter?
="SELECT * FROM VIEW_NAME A " &
IIF(IsNothing(Parameters!partynumber.Value),
"",
"WHERE A.PARTY_NUMBER = " & Parameters!partynumber.Value )
Usually when I used Oracle with SSRS, I would DECLARE all of the parameter and set them up front so you're query would be:
DECLARE :partynumber INTEGER = ?
SELECT * FROM VIEW_NAME A
WHERE (
A.PARTY_NUMBER = :partynumber
OR
:partynumber is NULL
)
And then set your parameter in the PARAMTER tab of the dataset properties.
Related
I have a Firebird database where I used a Stored Procedure named SP_SALES to generate quite a complex sales report. I now want to consolidate the sales reports from a few DB's into one report using MS Access. In Access I created a normal pass though query acting as a linked table and will do this for each database from where I can easily consolidate the reports. My issue now is that I have FROM DATE and TO DATE parameters in my stored procedure. So my pass through query in Access looks like this:
SELECT * FROM SP_SALES ('2019/01/01' , '2019/12/31')
The user should be able to define the FROM DATE and the TO DATE when pulling my consolidated report. So I have created a userform where this can be populated. The userform is named frm_CONSOLIDATED_SALES and the date boxes are named txt_FROM_DATE and txt_TO-DATE respectively. So I changed my Access query to look as follows:
SELECT * FROM SP_SALES ([Forms]![frm_CONSOLIDATED_SALES][txt_FROM_DATE] , [Forms][frm_CONSOLIDATED_SALES][txt_TO_DATE])
I am however getting a TOKEN UNKNOWN error when running the query. I am trying to stay clear from doing this in VBA as I am not sure how to do a pass through query in VBA. However, if I need to go that route any assistance will be greatly appreciated.
How should Firebird know anything about your database when receiving a pass-through query? It has no idea what [Forms]![frm_CONSOLIDATED_SALES][txt_FROM_DATE] is about other than invalid syntax.
So, before passing the query, adjust its SQL property to:
SELECT * FROM SP_SALES ('2019/01/01' , '2019/12/31')
using something like:
YourQuery.SQL = "SELECT * FROM SP_SALES ('" & Format([txt_From_Date], "yyyy\/mm\/dd") & "' , '" & Format([txt_To_Date], "yyyy\/mm\/dd") & "')"
I want to automate some of our Access Reports with a VBA script. But when I want to run them with DoCmd.OpenReport, I have the problem that every Report has a Popup for some Parameters coming from the underlying Query.
This is how the Parameter looks like in the Query:
PARAMETERS [Time] Text ( 255 );
I googled a lot and tried with:
DoCmd.OpenReport "B_My_Report", acViewPreview, , "[Time]= 423"
But this didn't work; the popup still comes and when I enter nothing, the query will fail because Time parameter is empty.
Is there a way I can call the Report with the Parameter value. I read a lot of Suggestion to remove the Parameter completely and use the where condition in OpenReport. But I can't change these Queries because they aren't made and maintained by me. I only have to run them sometimes. So I would love to have a solution without touching the Report or the Query.
If your Access version is >= 2010, consider the DoCmd.SetParameter Method.
This query is the Record Source for my report:
PARAMETERS which_id Long;
SELECT rmy.id, rmy.reportDate, rmy.gainOrLoss
FROM record_matYields AS rmy
WHERE rmy.id=[which_id] OR [which_id] Is Null;
So then I can assign a value for the parameter and open the report displaying only the matching record (id is the primary key):
DoCmd.SetParameter "which_id", 4
DoCmd.OpenReport "rptFoo",acViewReport
Or, because of the OR [which_id] Is Null condition in the query's WHERE clause, I can assign Null to the parameter before opening the report if I want all records included regardless of their id values:
DoCmd.SetParameter "which_id", Null
You can't. If you would open the query in VBA, you could supply the parameter. But since the report is the only one who calls the query, the query will ask for its parameter.
If you can't change the query, you'll have to live with it.
You can refer the parameter value from a form that will open this report using the syntax Forms![form name]![control name], so the query needs to be changed something like
Select * from [table name] where time_id= Forms![form name]![control name]
this will make sure the the query gets parameter from the form's control and it won't prompt parameter.
But it only works if you open that query when this form is kept open/loaded...otherwise it will prompt like parameter again.
The Docmd.setparameter in Access 2010 seems to be a very good suggestion where it keeps flexibility and good programming.
Good day.
I have an inventory application. When an item is moved into production a ticket is required to be printed with a customer name and the product name. I created the ticket as a report. I used the following query as the Record Source in the report and it works exactly as I want.
SELECT [PkgSize] & " " & [PkgUnit] AS Pkg, tblProducts.ProductID, tblProducts.ProductPrintName,
tblProducts.Grade, tblCustomers.CompanyName, tblOrderDetails.ODEPriority
FROM tblCustomers INNER JOIN (tblOrders INNER JOIN (tblProducts INNER JOIN tblOrderDetails
ON tblProducts.ProductID = tblOrderDetails.ODEProductFK)
ON tblOrders.ORDOrderID = tblOrderDetails.ODEOrderID)
ON tblCustomers.ID = tblOrders.ORDCustomerID
WHERE (((tblProducts.ProductID)=[Forms]![frmInventoryTransfers]![cboTransferProductID])
AND ((tblOrderDetails.ODEPriority)=1)
AND (([tblOrderDetails]![ODEQtyOrdered]-[tblOrderDetails]![ODEQtyProduced])>"0"));
The report is opened with the following:
DoCmd.OpenReport "rptProductPaperLabelTCTRlogo", acViewPreview
What I want to do is to move the query into my procedure because I need to change values of some items. For example, I will need to change the ODEPriority to a different number, such as 2 or 3 i.e. change it to a variable. This will trigger the ORDCustomerID to change but not the ProductID.
I have created a string from the query and tried
DoCmd.OpenReport "rptProductPaperLabelTCTRlogo", acViewPreview, , , , Qstring
but I get #Name? in all the text boxes. (I first removed the query from the record source in the report.)
I have tried to use a querydef but can't seem to get the syntax right.
Can someone help me with how to move the query into a procedure to make the report dynamic.
Thanks
The OpenArgs parameter is simply passed to the report. It isn't automatically used for anything, but available in the Report event procedures.
So in Report_Open(), you can do:
Me.RecordSource = Me.OpenArgs
and it should work.
Side note: in the last line, it should be >0 instead of >"0"
I need to load about 40 flat files into 40 different tables and log each one into a stats table after it's loaded. I've named my tasks to match the table names and created onPostExecute events with an execSQL task in each of them (they're all copies of the task I made first.)
I have a variable at the package scope containing the SQL I'd like to execute including a reference to the system variable #[System::SourceName]:
"INSERT INTO db.TableStatsHistory SELECT * FROM db.TableStats WHERE TABLENAME = '" + #[System::SourceName] + "'; " +
"DELETE FROM db.TableStats WHERE TABLENAME = '" + #[System::SourceName] + "'; " +
"INSERT INTO db.TableStats
SELECT t.tname ,CURRENT_DATE ,rcnt ,sum_currentPerm FROM
(SELECT databasename, TABLENAME AS tname FROM dbc.TablesV) t INNER JOIN
(SELECT databasename, TABLENAME AS tname, SUM(currentPerm) AS sum_currentPerm FROM dbc.TableSize GROUP BY 1,2 ) ts ON
t.databasename = ts.databasename AND t.tname = ts.tname INNER JOIN
(SELECT '" + #[System::SourceName] + "' AS tname, COUNT(*) AS rcnt FROM db." + #[System::SourceName] + ") u ON
t.tname = u.tname WHERE t.databasename = 'db' AND t.tname = '" + #[System::SourceName] + "'"
When I only had one task enabled for development, it ran fine, but now that I've pasted that task into 39 other onPostExecute events, it says:
Error: The variable "System::SourceName" was not found in the Variables collection.
The variable might not exist in the correct scope.
I'm not real clear on the concept of 'scope' for SSIS variables, but the examples I've seen say to create your user variable at the package level. If I first click on a task in an event and then open the variable's Expression window, it evaluates just fine.
I'm hoping I don't have to create multiple variables and/or tasks at each scope to get this to work, I only want the SQL statement in one place referenced by each data flow task's onPostExecute event, but I read here
Scope
You can change this property setting only by clicking Move Variable in the Variables window.
A variable is created within the scope of a package or within the scope of a container, task,
or event handler in the package. Because the package container is at the top of the container
hierarchy, variables with package scope function like global variables and can be used by all
containers in the package.
so why can't the package find the system variable?
Thanks for any help,
-Beth
I can get it to work if I create one variable at the postExecute scope with a different path for each ExecSQLTask and the exact same expression, but if there's a better way to reference the expression across tasks in events, please let me know.
Thanks.
I'm also trying to parameterize the execute sql task sqlStatementSource variable with a value like
DELETE FROM db.TableStatsHistory WHERE TABLENAME = '#[System::SourceName]'
and LastUpdated = CURRENT_DATE;
but that's not working either. It doesn't give me a 'parameter mismatch' error like when I create a parameter within the task, but it behaves as if the system variable value is blank or null.
Basically, I want a method equivalent to SQL Server stored procedures with parameters, but I don't think Teradata has anything like that. I'm thinking now I should store the SQL in a table on Teradata and look up the SQL to execute with the embedded parameter token.
Having the "System::SourceName" is the issue. It has the scope that is not compatible with the design of the package.
Not sure how exactly you designed your package, but an appropriate fix could be in creating a User (package level) variable that gets the value of "System::SourceName" and then you can use it in the PostExecute event.
I have this qry in access, if I go into its design it has a criteria (which as I understand it is a parameter).
The Report this qry is based off of works great, click on it a little thing pops up asks the required info and off it goes. In code I am trying to do this and get a
Run-time error '424'
Object Required
the offending line:
qdf.Parameters("Insurance Name").Value = inputStr
Lines before it:
Set qfd = CurrentDb.QueryDefs("qryInsGrpRoster")
Dim inputStr As String
inputStr = InputBox("Enter Insurance")
'Supply the parameter value
qdf.Parameters("Insurance Name").Value = inputStr
inputStr definitely equals the value, it fails though.
The criteria line in the qry is:
Like "*" & [Insurance Name] & "*"
Do I need the likes and all that to set that parameter?
in Access 2010 and 2013
This uses DAO and might be of interest
DIM MyQryDef as querydef
Dim a as string
a = ""
a = a & "PARAMETERS Parameter1 INT, Parameter2 INT; "
a = a & "SELECT f1, f2 FROM atable WHERE "
a = a & "f3 = [Parameter1] AND f4 = [Parameter2] "
a = a & ";"
Set MyQryDef = currentdb().CreateQueryDef("MyQueryName", a)
MyQryDef.Parameters("Parameter1").Value = 33
MyQryDef.Parameters("Parameter2").Value = 2
' You could now use MyQryDef with DAO recordsets
' to use it with any of OpenQuery, BrowseTo , OpenForm, OpenQuery, OpenReport, or RunDataMacro
DoCmd.SetParameter "Parameter1", 33
DoCmd.SetParameter "Parameter2", 2
DoCmd.Form YourFormName
' or
DoCmd.SetParameter "Parameter1", 33
DoCmd.SetParameter "Parameter2", 2
DoCmd.OpenQuery MyQryDef.Name
See here:
https://msdn.microsoft.com/en-us/library/office/ff194182(v=office.14).aspx
Harvey
The parameters property of an Access Query is read only.
You have basically two options here that I can think of right off.
The first is to just completely rewrite the SQL of the saved query each time you need to use it. You can see an example of this here: How to change querydef sql programmatically in MS Access
The second option is to manually set the RecordSource of the report each time it opens. Using this method you will not use a saved query at all. You'll need to set/store the entire SQL statement in your code when the report opens, ask for any input from the user and append the input you get to your SQL statement. You could setup a system where the base SQL is stored in a table instead but, for simplicity, that's not necessary to achieve what you're trying to do here.
MS Access does allow you to use parametrized queries in the manner you're attempting here (not the same code you have), but as far as I know, it would require you to use Stored Procedures in MS SQL Server or MySQL and then you'd need to use ADO. One big downside is that Access reports cannot be bound to ADO recordsets so this isn't really an option for what you're trying to do in this particular instance.
Seems like a typo. You're creating the object named 'qfd', and trying to use the object named 'qdf'
Set qfd = ...
and then
qdf.Para...
I like to put Option Explicit in my modules to help me find these types of issues.