Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
So we've started grouping together data in a couple of different ways-- matrixes and tables--but we haven't filtered anything yet. We haven't restricted the amount of rows we're bringing back from the database from any of these tables, so let's do that now. Creating a new report. You should be getting familiar with this general process. We first need the data source. And I do this multiple times because it is a good idea to start to get very familiar with the different things you're asked for every time you create a data source. We will get into sharing them a little more further down the line.
So I'll connect to my SQL 2012 Server and go to AdventureWorksLT. It doesn't really matter which one I'm going to; I just need some data to play with. Back into Datasets, let's add a new one. I could be descriptive with this. I want to show products, but not just all products, products by category. The name of course does nothing special, but it will allow us to read it later on and realize what this is meant to represent. So selecting the Data Source I'll jump into Query Designer.
Drill down into the Product Table. I'll go for ProductID and Product Name and Color and ListPrice. We could run this query just to see what we'd get back, and of course it's going to be everything at this moment, but I want to restrict them by category. So what I'm going to do is in this Filter section apply a filter. If I come over to this little Filter icon here, Add Filter, I'll click it, it asks, what do I want to filter on? What column am I restricting my information based on? And it's dropped in with ProductID, but the one I'm actually interested in will be a CategoryID, so I'll select ProductCategoryID.
We have this Operator option, where it is, where it is not, is any of, none of, more than, less than, and so on. I'm going to say ProductCategoryID equals, or is, double-click in that area, 35, and then let's test that. I run the query this time and I only get three results back, because I'm getting the products that are in that particular category. And sometimes this is all you need is this very literal fixed restriction, but there will be a lot of cases where you want to change it.
So first, just show me the products in the Mountain Bikes category, then show me the products in the Hat category or the Bags category. So when we want to do that, we need to use parameters, so that this value can be changed when we run the report, and doing that in the query, in the dataset, very easy. I can just come along here and check that Parameter checkbox, click OK, and I'm done. Now, if you're curious and you like reading your SQL, I can see that what I've got here is a regular WHERE clause in my select statement. We're selecting those columns from the Product table as long as the ProductCategory ID is equal to, and here we're using this @ProductCategory ID.
That is the name of a parameter that we can then change when this report runs. Okay, so where's that parameter? Well, let's go see. I'm going to come out of this dataset, just click OK. And over now in my Report Data section in Report Builder, if I expand the Parameters folder, I should have a parameter showing up here, ProductCategory ID. Okay, what does this actually mean? Well, first, I better have something on my report to allow us to see this. First, just give it a title, Parameter Example, and I'm going to insert a basic table.
Use the Table Wizard. We're going to fuel it from the ProductsByCategory dataset. Click Next. And I'm going to go really simple here. I'm just going to select ProductID, Name, Color, ListPrice. I'm not even going to bother grouping them in rows or grouping them in columns. I could do, I just don't need to for what I'm trying to illustrate here, which is just restricting the rows we bring back by the category. Click Next. I have no Layout options because I'm not doing any grouping, and then I'll just pick, say, Corporate, Finish, and we're done here.
Drag that a little wider, and I'll run this to preview this report. So because I filtered on 35, that is considered the actual default ProductCategoryID. I can see up here that just by having a parameter, I have this place I can now type into in the report. It's got 35 selected. I could type in 21 and press Enter and now I get all the products in the category of 21, or 22. If put in a category that doesn't exist, I'll get nothing. So just the fact that we have that parameter defined, Reporting Services is giving us this area at the top we can type into.
Now, of course I'm just in the preview of Report Builder right now, but to prove that this works on the website itself, we'll switch back into Design view and I'll hit the Save button, and I'll save this to the Report Server. I'll just call this Parameter_Example. You don't need to use underscores in your naming. You can use spaces. I just prefer underscores. If I switch back to the Report Manager website and just refresh that, we can see the Parameter_Example one here. If I click into that to view it on the website, we have the same idea up here, the area that we can type into. It's coming up with the default of 35 because that was defined in the dataset, but I can change that to anything else, like 21, and in this case either quick Return or I could click View Report explicitly to refresh that.
And this works fine. Okay, it's not the most friendly page. Right now we need to know the numbers for these categories to be able to go to a particular one. I'd have to know what 21 represents, or 22, or 25. So next, we're going to see how to change the appearance of this Parameter area and make it more helpful.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 97068 Viewers
61 Video lessons · 84386 Viewers
71 Video lessons · 68602 Viewers
56 Video lessons · 101085 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.