So I have two datasets called Employee and EmployeeData. Employee is the main dataset that is used by the report and I want to add a filter to it. The filter parameter is created as EmployeeID. Employee has columns Name, Department, Job, etc. EmployeeData has columns Name, EmployeeID, Address.
I'm trying to filter using EmployeeID on Employee so I need to do some sort of join with EmployeeData using Name as the key. This would be easy in SQL but since I'm new to SSRS, I don't know what the syntax of the expression would look like here.
Thanks
Create another parameter #employeename and set it's default value to the employee name from the employeename dataset, then use that parameter to filter the Employee dataset based on the like operator and the name field.
SSRS is very sensitive to parameter order, so you may need to delete and recreate them in the correct order.
Related
I have two tables:
'tableStudent' - a list of students given an ID number by the table, with following columns:
student_ID
last_name
first_name
and 'tableProject' which gives each project an ID and will be used to store information about the students involved in the project. Students will work in pairs on the project. This table includes the following columns:
project_ID
project_title
student1_ID
student2_ID
The columns student1_ID and student2_ID are combo-boxes that link student_ID to the student names.
I want to create a form that can be used to record students involved in a project. I want to be able to select the student IDs and have the student names autofill on a form.
I can make a form that autofills, but only with one student with this SQL:
SELECT tableProject.project_ID, tableProject.project_title, tableProject.student1_ID, tableStudent.last_name, tableStudent.first_name
FROM tableStudent INNER JOIN tableProject ON (tableStudent.student_ID = tableProject.student2_ID) AND (tableStudent.student_ID = tableProject.student1_ID);
When I add Student 2, I get a duplicate error on the student names. How do I indicate that the two names belong to different students? This is the code I'm generating:
SELECT tableProject.project_ID, tableProject.project_title, tableProject.student1_ID, tableStudent.last_name, tableStudent.first_name, tableProject.student2_ID, tableStudent.last_name, tableStudent.first_name
FROM tableStudent INNER JOIN tableProject ON (tableStudent.student_ID = tableProject.student2_ID) AND (tableStudent.student_ID = tableProject.student1_ID);
Any help appreciated!
Options for displaying related info from lookup table:
Use Access query designer to build form RecordSource. Pull tableStudent into query designer. In your case pull in twice - second instance will get named like tableStudent_1. Join each to one of the student fields. Bind textboxes to both sets of lookup table fields and set them as Locked Yes to prevent edit.
Don't include lookup table in form RecordSource at all. Include all student info in combobox RowSource. Expressions in textboxes refer to combobox columns by index, index begins with 0: =[comboboxName].Column(1)
DLookup() domain aggregate function, however, since your tables have a relationship, this is an inefficient method.
For all options, set textboxes with TabStop No.
i have a simple ssrs report in which i have one multiple values parameter.
I want to use the returned values to execute some queries on another table, but when i create the second dataset and i try to get the list of returned values i get ssrs error.
Example:
Multiple values parameter: #MyParam1
Anthony
Michael
Mary
I want to select for example only the values that starts with 'M' and populate with the filtered data another multiple values parameter called #MyParam2.
When i try to parse #MyParam1 in my dataset query i get the error because teh returned value is an array type. I read on some blogs that i can use the JOIN function , but how i can use directly in the Dataset TSQL code?
thanks a lot!
You could use the original table for the parameters and filter it by your selection for your main query.
SELECT FIRST_NAME, USER_LAST_NAME, USER_ID
INTO #TEMP_USERS
FROM USERS
WHERE FIRST_NAME IN (#MyParam1)
Then JOIN on the TEMP table to filter for the parameter selections and add your criteria.
JOIN #TEMP_USER U ON U.USER_ID = X.USER_ID AND U.FIRSTNAME LIKE ('M%')
I am creating an SSRS matrix report in which Loans are mapped with primary keys of Employees originated the loan, so the tables looks like:
<table><tbody><tr><td>LoanID</td><td>Employee</td></tr><tr><td>101</td><td>1</td></tr><tr><td>102</td><td>2</td></tr><tr><td>103</td><td>3</td></tr><tr><td>104</td><td>2</td></tr><tr><td>105</td><td>1</td></tr><tr><td>106</td><td>2</td></tr></tbody></table>
<table><tbody><tr><td>Employeeid</td><td>Employee Name</td></tr><tr><td>1</td><td>A</td></tr><tr><td>2</td><td>B</td></tr><tr><td>3</td><td>C</td></tr></tbody></table>
When I create the matrix using first table I get:
<table><tbody><tr><td>Employee</td><td>Count Of Loans</td></tr><tr><td>1</td><td>2</td></tr><tr><td>2</td><td>3</td></tr><tr><td>3</td><td>1</td></tr></tbody></table>
But I wanted result like:
<table><tbody><tr><td>Employee</td><td>Count of Loans</td></tr><tr><td>A</td><td>2</td></tr><tr><td>B</td><td>3</td></tr><tr><td>C</td><td>1</td></tr></tbody></table>
How can I relate the name of values in rows groups to take out the names of Employees?
It is generally better to join tables in the source system when you can. To answer your question, you can use the Lookup function to get the Employee Name from the second dataset. In this case it would look something like this:
=Lookup(Fields!Employee.Value, Fields!EmployeeID.Value, Fields!EmployeeName.Value, "DataSet2")
In other words, for each row, it is looking up the employee ID in the second dataset and returning the name.
I want to create tablix report in the following format:
Where Customer / Orders / Inquiries are seperate tables with customer ID as primary key. How can I create this kind of tablix report where I can display all information in single row by customer ID?
Link to the report format
If you don't want to create one dataset that joins all the tables together you could create multiple datasets one for customer, orders, and inquiries and use the lookup and lookupset function by passing in the CustomerID to each.
You would paste expressions that look similar to these in the textboxes of the table
Lookup(source_expression, destination_expression, result_expression, dataset)
LookupSet(source_expression, destination_expression, result_expression, dataset)
=JOIN(LookupSet(Fields!CustomerID.Value, Fields!CustomerID.Value, Fields!OrdersthisQuarter.Value, "orders"),"")
=JOIN(LookupSet(Fields!CustomerID.Value, Fields!CustomerID.Value, Fields!InquiriesthisQuarter.Value, "inquiries"),"")
=Lookup(Fields!CustomerID.Value, Fields!CustomerID.Value, Fields!Contact.Value, "orders")
=Lookup(Fields!CustomerID.Value, Fields!CustomerID.Value, Fields!Region.Value, "inquiries")
Lookup Function reference
LookupSet Function reference
You need to write a query that joins all the tables and creates a data set. I would recommend using stored procedure for your query.
Add data set & data source to SSRS.
Create the tablix report.
Please make your data set does not return to many rows because it will complicate browsing & export performance.
More details: http://msdn.microsoft.com/en-us/library/dd220592.aspx
Heres a reference to creating a dataset in SSRS. SSRS Dataset
I"m assuming you're query and the embedded dataset code would look something like this if you join on cusotmerID:
SELECT customerID
,customername
,contact
,region
,ordersthisquarter
,inquiriesthisquarter
FROM Customer C WITH (NOLOCK)
JOIN Orders o WITH (NOLOCK) ON c.CustomerID = o.CustomerID
JOIN inquiries i WITH (NOLOCK) ON i.CustomerID = c.CustomerID
if you paste this as a dataset you can use the fields from this dataset on a tablix.
When you build your table, create a group on customer ID and that should roll up to one customer and will display the multiple orders and inquiries they have. creating groups
I created a SSRS report with a dropdown to parameterize data being reported. This works fine. I now need to add another parameter to filter the report a little further. For example, I have a location dropdown that shows area, country, region, etc. I need to add another dropdown that is dependant on the first dropdown. So if I select "country" in the 1st dropdown, I show the list of countries in the 2nd dropdown or if I select Region - I show list of Regions in the 2nd dropdown. Country, Area, Region data is stored in different tables. So basically my query needs to be smart enough to run the appropriate sql based on 1st dropdown selection.
Thanks so much for any assistance given.
One of the powerful features of Reporting Services is that everything is an expression, including the dataset's SQL statement.
Let's say your first parameter (the one that describes what to select) is called Location and it selects a list of locations such as country, region, etc. Perhaps you get that from a table which has a LocationId and a Description like so:
SELECT LocationId, Description FROM Locations
You hook up the Location parameter to this query to get your drop down list of location selectors for the Location parameter.
Now create a second parameter called Select where we want to select from a list of countries or regions. To keep it simple, I'm going to assume there are only two locations: Country with a LocationId of 1 and Region with a LocationId of 2.
Create a new dataset called Selections and manually add fields to it called Id and Description. Hook up your Select parameter to this dataset. Now for the SQL Statement for the Selections dataset, enter the following expression:
=IIF(Parameters!Location.Value = 1,
"SELECT CountryId AS Id, CountryName AS Description FROM Countries",
"SELECT RegionId AS Id, RegionName AS Description FROM Regions")
So, where the Location parameter is set to 1 (Country) you select from the Countries table otherwise you select from the Regions table. You alias the field names so you get consistently named fields for your dataset for use in the Select parameter query. Obviously, you can extend this to more selections as required.
You get the idea but this is a little fragile - whenever you want to add a new location type you have to go through all your reports and update the SQL statement for the Selections dataset. That's tedious and no one wants that job. What we want is an automated system where all reports get the new selections whenever they are added.
So let's add a column to the Locations table, called SQLStatement. For the Country row, this will have the value:
SELECT CountryId AS Id, CountryName AS Description FROM Countries
For the Region row, the SQLStatement field has the value:
SELECT RegionId AS Id, RegionName AS Description FROM Regions
Now the Locations table has the value of the SQLStatement in it for the Selections dataset. You can't use this directly (your dataset would just return the value of the SQL statement field, not execute it) but you want to have something that returns this string as the expression to use for the SQL statement for the Selections dataset. Custom code can be used to do this. So the expression to use for the Selections dataset will be something like this:
=Code.GetSQLStatement(Parameters!Location.Value)
And then you have custom code function like this (significant parts left out):
Public Function GetSQLStatement(LocationId As Integer) As String
Dim SQL As String
SQL = "SELECT SQLStatement FROM Locations WHERE LocationId = " + CStr(LocationId)
' Connect to database, get SQLStatement field
GetSQLStatement = <Field Value>
End Function
When you want to add another location selection, for example continents, all you have to do is add another row to the Locations table, say LocationId = 3, Description = Continent and SQLStatement = SELECT ContinentId AS Id, ContinentName AS Description FROM Continents and now every report you have that selects by location will be able to use Continents.
First dataset add this SQL
Select ContryName, CountryID From Country
Assuming the name the above dataset's parameter is #country add the following SQL on the second dataset
Select RegionName, RegionID From Region
Where CountryID IN( #country)
It is very simple. Let’s assume that the data of the table “ONE” as follows:
**Location_Type** **Location**
Country India
Country Sri Lanka
Country China
Country Japan
City Bangalore
City Hyderabad
City Delhi
Ex:- Query for the Report parameter (#Location_Type1):
Select Distinct Location_Type from One
Query for the second Report Parameter:
Select Location from ONE where Location_Type = #Location_Type1.
Please let me know if it is not clear.