can we use the same filters to create cascade parameters and individual parameters in SSRS? - sql-server

I am creating a report which contains 3 parameters COUNTRY, STATE, and CITY. I have already created a cascade parameterized report which means the CITY result is based on the STATE result and the STATE result is based on the COUNTRY result. But what I want now is, in the same report and parameters if I just choose only COUNTRY or only STATE or only CITY, I want results as well. It should not give me any errors. That means if I only choose country and run the report it should show the result and the same with STATE and CITY. On the other hand, cascade parameters should also be active. Is it possible? If yes what will be the process and if not what would be the best option? The page will be used by multiple users throughout the website. Do I need to work on the code or the SSRS report or both?

You should be able to do this easily (I think)...
You already have Country -> State -> City setup and I'm assuming the query for the available values will be something like...
SELECT State from myTable WHERE Country IN(#Country)
... and so on.
I'm also assuming that your final dataset query, the one that actually gets the report data have a WHERE clause that filters on City. e.g.
SELECT * FROM myMainTable WHERE City in (#City)
So, all you should need to do is to set the default parameters to the same dataset query as the available values.
When the report runs, all Countries will be selected, which means all states will be available/selected and therefore all cities will be available/selected.
There is also another, more complicated method which means the user chooses what to filter on first and then makes selections which in turn populate the next drop down but I think it's probably overkill. If this sounds of interest though, let me know and I'll dig out the answer I wrote a while back for somebody else.

Related

Google Data Studio - Is it possible to filter across data sources

I have seen the link below which explains that it is possible to create a filter on one field between sources by generating a calculated field and then assigning the same field ID to both fields for filtering purposes:
Using the same filter control for two different data sources
But my question is whether or not it is possible to make that particular field (that is now shared between 2 data sources) dependent on other filters that are tied to 1 of the data sources?
Example would be:
One dataset with country name and city name
One dataset with city name and population
I've generated a calculated field to be able to filter on city name since they now share the same field_id.
What I'd like to do is use a control that selects country from dataset 1 and then automatically filters city_name in both datasets.
I realize I could just pull country name into my dataset in the example above, but in my real dataset there are a significant number of fields I'd be looking to be able to use for filters.
If a filter is set, all charts and filters are updated with that setting. However, it would be a huge mess, if any of these objects would automatically changes the filters again. Then all object would be updated again and the filter setting could be changed once more, thus ending up in an infinity loop.
Therefore, a filter can only apply to a field. If this should cause further filtering an user action is needed. It would be possible to write a customer vizualisation, which would mimic an user action, but again it could end in an infinity loop.

Bound combo box in form does not always update table

I'm struggling with a problem which I can't work out is due to a logical error, a design error or both. Or maybe it's something else entirely.
I have created a simple customer services database and form based user-interface for my company. When a user answers the phone they are supposed to log the call in the system if it is an issue relating to a product.
Sometimes a chain of stores which we have a special relationship with calls up on behalf of customers and we take their reference number and give them ours. This system actually works pretty well if I may say so myself (!), but I noticed after a while that when this store calls up and gives us their number, when they are logged into the system their branch number/name is not updated in the table record.
Here is a summarised outline of the relevant database tables. I renamed the store to SpecialStore:
Issues
IssueReference
ProductID
CustomerID
SpecialStoreBranch
Customers
...
Products
...
SpecialStore
SS_ID
City
Address
The idea is that even if it is either a customer or the store with their own IDs, the products are still stored in the same Products table, just with either the CustomerID or SS_ID filled in. Then when issues are logged, the store or customer is set and logged against a product.
In my main form I have a variety of boxes for a new issue to be filled in. There are combo boxes to select the CustomerID, ProductID etc, and of course the SpecialStoreBranch. These are all bound to the table, and the combo boxes all have row sources relating to their particular table. E.g. CustomerID combo box is a list of the IDs in the Customers table. (This is filtered to the required one elsewhere in the form.)
The Issues table SpecialStoreBranch field has the following query as its Row Source:
SELECT SpecialStore.[SS_ID], [SpecialStore].[City] FROM SpecialStore;
This is the same row source for the combo box on my main form.
The Column Count is 2, with the Bound Column as 0 and the column widths, if necessary, are 1cm;2.544cm.
My main form combo box SpecialStoreBranch has the other attributes:
Limit to List = yes
Allow Value List Edits = no
Inherit Value List = yes
Show Only Row Source Values = no
On the form the CustomerID and ProductID store correctly when the record is saved, and they are also from combo boxes. The form refreshes to update those fields when another part of the form (adding new customers and products) is changed. Could this be why the SpecialStoreBranch does not update? What am I missing? Is there a way to test this? I have been trying to run user tests to see if it ever works, but all I know is that it doesn't always set. If I have forgotten a piece of information let me know.
Edit:
Looking here: BoundColumn-Propery, I'm not sure if setting the bound column to 0 is doing what I think it's doing. But even then it should still use that id number to input into the table I would have thought and if they are all the same, what does it matter. When I tried setting it to 1, it took the text value in the table. Confusing!

filter data from one table based on second table without duplicates

Note: I'm working with a large complex database, so for clarity's sake I have simplified the set up below.
I struggled a bit with how to title the question since it's a bit of a complex question. I hope it's accurate enough....
A bit of background first:
I have an Access 2010 database that contains a one-to-many relationship between a table Called "Products" and a table called "Datasets" (ie I have a bunch of products, and each product has multiple datasets). Each has an autonumber key field (p_ID and d_ID respectively) as well as numerous other fields.
I have a form (lets call it frm_Main) that has two subforms: sub_Products (based on the "Products" table) and sub_Datasets (based on the "Datasets" table). On the main form I have a control ctrl_SelectedProduct which is linked to [sub_Products]![p_ID] to see which record in sub_Products is selected / has the focus, and the sub_Datasets subform is linked to this control so that it only displays Datasets records that belong to the selected Products record.
On the main form I also have a number of controls that I'm using for filtering the data in the subforms. For example, I have a control ctrl_Category. I have this control coded so that when the user changes the value of the control, a filter is applied that limits the records in sub_Products to only those that have a p_Category value equal to whatever is chosen in ctrl_Category. If the control is blank, it will show all records. All this works great when if comes to filtering based on fields in the Products table.
Now the problem:
My problem is that I also want to be able to filter based on fields in the Datasets table. For example, Datasets has a field called d_Status. I want the user to be able to chose the status in a control (ctrl_Status), and based on this:
1) sub_Products will be filtered to display only those Products records that have an assotiated Datasets record (or records) that has d_Status equal to whatever was chosen in ctrl_Status
then
2) when a Products record is selected in this filtered sub_Products, sub_Datasets will only show the Datasets records that has d_Status equal to whatever was chosen in ctrl_Status
I know how to do part2. But I have no idea how to get part1 to work. Since sub_Products is currently based on the Products table, which does not have the d_Status field, I have no way to filter it based on that field. Thus, I'm assuming my first step will be to change my setup so that sub_Products is based on a query that combines the two tables (or at least adds the d_Status field).
If I do that, however, I get duplicate Product records. I can't use the query's Unique Values property because if I have a product that has two datasets, one with status "Current" and a one with status "Archived", then those aren't considered duplicates, and the product info is there twice. If I don't have the status field displayed, it shows only unique products initially, but then I can't subsequently apply a filter based on that non-displayed field.
I also tried basing sub_Products on a Totals query in order to utilize the Group By functionality, but I still couldn't get it to work right. Even if I could I don't think that's the best solution, because you can only have 10 fields with Group By, and my Products table has more than 10 fields that I need displayed in sub_Products.
I feel like I'm now just going around in circles and am at a loss of what to try from here. Please help!
Couldn't you add something like this?
Private Sub ctrl_Category_AfterUpdate()
Form_frm_Main.Recordsource = "Select * from Products where p_ID IN(" & _
"Select p_ID from Datasets where d_Status = " & _
Me!ctrl_Category.Value & ")"
End Sub
Alternately, you can access the childform via the parent of the other child form.
This is a non-working snippet just to give you the idea:
Me.Parent.otherChildFormName.Form.Recordsource = whatever

SSRS parameters, populating the available fields list

When producing a list of available parameter properties, rather than manually typing each persons name in one by one, is there any way of just populating the data from the table/view which holds all the possible names?
I assume its in the circled box however all that does it let me point to a dataset and then field which I have tried selecting StaffName (being the field that is the one I'm using) if I then run the report it falls over.
Add a new dataset to the report, maybe called StaffMembersDS. The SQL for it might look like:
SELECT Id, Name
FROM StaffMember;
Then assign Name to Label and Id to Value.
BTW if this is related to your last question you're going to run into the trouble that when a user picks a staff member name from the drop down list they are picking only one value. So for your case you might want the Value field to be tied to Name as well as the label. That would allow you to use the query in your last question - SSRS Parameters - which collects related Id values.
SSRS's concept of a query is largely tied to a data set that you define in Report Data.
When you choose 'Use a query', you should be choosing a pre-defined query from Report Data. Of course, the good news is that you can define these yourself.
So let's take your example. You want your possible parameter options to be StaffNames.
Create a new dataset in Report Data. It should return all possible staff names for your report.
Something like:-
SELECT DISTINCT
StaffName,
StaffID
FROM
MyReportViewOrTable
Once you have defined this dataset, you should be able to use it as a source of parameter values.

Order data using values stored in another table

I've been using cakephp for a while, but have not learned all the ins and outs yet so I may be missing something simple. Or the problem may lie with my database structure. Either way, if anyone has any idea of what I'm doing wrong, please share.
Is there a way to order the data returned by cakephp's find using values stored in another table?
I am creating custom form fields on a per category basis, so when I choose a particular category to post in, custom fields will be added to my form. I have 3 tables: Posts, Fields, and Answers. The Posts table stores the basic static information for the post, such as id, category_id, title, and description. The Fields table stores the custom field data, such as category_id, field_label, field size, etc. The Answers table stores the values that are entered for particular fields, such as post_id, field_id, value.
I am trying to display the posts for a particular category, and create html table headers on the fly, using select fields, set by a column toggle in the fields table, and also select the answers associated with that particular field and post.
I am able to select all the data I want, and paginate everything just fine, but what I can't seem to figure out is how to order the data using one of the dynamic column values. For example, if I have year, make, and model as 3 custom fields, I would like to click the year column to sort my results by the year values, and if I click the make column, I would like to sort my results by the make values, etc.
I know how to order the results by a particular field inside the posts table, such as id or title, but is it possible to order using the custom fields? Am I setting up the database and/or something else wrong, and if not is there are particular cakephp method or sql command that I need to use in order to sort by the custom fields? I'm not really well versed in complex sql commands.
Thanks.
I'd suggest you pass the field name and sort direction in the URL (GET param). So when you have your table header link, form it so that it links to a URL as so:
http://somesite.com/pages/index/sort:customfield1/dir:asc
Then when you're grabbing the data from the db in your find() query, include the named parameters as the order parameter that can be sent to find.
You'll need to determine a default sorting column and direction. Maybe have that be selectable with a boolean field in the schema -- if there are no parameters sent to the action above, pull the field from your other table that has default set to true in the record.
To clarify: when a user visits a given action, first you'll pull the custom fields from the other table. Then using those fields (either the default as mentioned above, or the named params passed in the URL) form the query for the actual data, using the order parameter.

Resources