I want to create a report based on 3 tables called Physician, Credentials and Insurance. All these tables are related to Physician and linked by physician Id.
I want to display rows based on physician id but suppress the duplicate values. How to display the physician, credentials and insurance details in one report based on physician id?
Here the problem is one physician contains more than one credential and insurance details. Suppose for physician id=1 he contains credentials like A,B and and insurance like C,D my report is coming like this
physician id credentials insurance
1 A C
1 A D
1 B C
1 B D
BUT I want my report like
physician id credentials insurance
1 A C
B D
SO I want to display the details once and want to hide the duplicate values
Is there any possibility by using sub reports please mind I am using SQL Server 2005 and ssrs 2005.
Sorry for my bad language plz help for this thanks #anil#
Add a 3 column table to your report
Create a group on PhysicianID
Make PhysicianID the value in the first column on the group header row
On the 2nd column, add a List.
Right click the List and click properties --> Edit details group...
Select =Fields!Credentials.Value in the group on expression dropdown
Add a textbox to the list and set value to =Fields!Credentials.Value
Follow steps 4-7 for the 3rd column
Summary:
Add a List to a group header and group the list by the value you want to get the "distinct" value, the put that value in a textbox, which will then repeat for that group.
Related
I have a table that contains the columns name age and Dept. I am new to report builder and wanted to know if there is a way possible to create dynamic tables based on distinct departments in the base table
Below is the base data
and this is how I want this to be represented in SSRS dynamically based on distinct items in the Dept. column
Thanks in advance!
Just add a Row Group to your table that grouped by Dept.
If you click the existing table you should see one of more row groups in the groups panel below the main design window. There might be just a single "Details" row group. Right click the row group and add a parent group, select Dept as the column to group by and that's it.
Figured this out.
Can use a list and add the desired table in there and then add in a group for the column required in the Group properties of the row
I am trying to write a BigQuery to get distinct values from one table say ABC
select distinct name from dataset.abc
1
2
3
4
now I want to insert these values to another table say XYZ, which also contains column as name and another column as company.
Note: the company column can be duplicated as I want the to have all 4 rows against every company to be inserted in table ABC.
I need a BigQuery to do this dynamically instead of updating every dataset manually every time.
P.S. Sorry if my question is not as per standards as this is the first time I am posting on Stackoverflow.
I have 3 tables, all SharePoint lists. I am trying to create a query that will show me all of the required DQ_File Forms that do not have an attachment in the DQ_File.
DQ_File_Lookup is a lookup table for the description field in the DQ_File. It also has the "DQRequired" flag I am looking for to see all of the required fields that do not have an attachment.
I have included a screen shot showing the table layouts and relations.
Any help would be appreciated, I am sure I am just overlooking something obvious.
A example would be as follows:
Employee Name | Document Name
You would have employee Joe and he has forms A,B,D out of a possible forms A,B,C,D,E,F so he would be missing forms C,E and F.
So the employee name would come from the employee table, and the document name needs to get passed through the DQ_File Table from the DQ_File_Lookup
the way I thought to do it was to get it to show all documents from the DQ_File table that are missing, that I can do. But that only shows the information that has an entry. There are certain forms that are required for every employee that I want to be able to see if a employee is missing any of those forms.
Using what #June7 posted below I got it to work, and it now will show me all 15 documents that are required for every driver. But when I add the attachment field from DQ_File it shows them all as zero attachments, when I know some of them do indeed have attachments already.
Here is a screen cap showing this.
Williams in particular should only have about 5 documents that should be on this list, but instead it is showing like all 15 are missing.
Here is the SQL from the combined query:
SELECT [qryEmployees+DQFileLookup].Last, [qryEmployees+DQFileLookup].Description, DQ_File.Attachment
FROM DQ_File RIGHT JOIN [qryEmployees+DQFileLookup] ON DQ_File.EmployeeNo = [qryEmployees+DQFileLookup].EmployeeCode
WHERE (((DQ_File.Attachment.FileURL) Is Null) AND (([qryEmployees+DQFileLookup].CURRENT)=True) AND (([qryEmployees+DQFileLookup].DRIVER)=True) AND (([qryEmployees+DQFileLookup].DQRequired)=True));
If you want to know which required docs employees do not have, then need a dataset of all possible combinations of employees/docs. Then match that dataset with DQ_File to see what is missing. The all combinations dataset can be generated with a Cartesian query (a query without JOIN clause) - every record of each table will associate with every record of other table.
SELECT Employees.*, DQ_File_Lookup.* FROM Employees, DQ_File_Lookup;
Then join that query with DQ_File.
SELECT Query1.EmployeeID, Query1.First, Query1.Last, Query1.ID, Query1.Title, Query1.DQRequired, DQ_File.Description, DQ_File.EmployeeNo
FROM DQ_File RIGHT JOIN Query1 ON (DQ_File.EmployeeNo = Query1.EmployeeID) AND (DQ_File.Description = Query1.ID)
WHERE (((Query1.DQRequired)=True) AND ((DQ_File.EmployeeNo) Is Null));
Advise not to use exact same field names in multiple tables. For instance, Title in DQ_File_Lookup could be DocTitle and Title in Employees could be JobTitle. And there will be less confusion if ID is not used as name in all tables.
It seems unnecessary to repeat Title and [Compliance Asset ID] in all 3 tables.
Strongly advise not to use spaces in naming convention. Title case is better than all upper case.
Lets assume I have 2 tables: Projects and Employees. Each project got one responsible employee that I chose as a Lookup Value from the Employee table.
Now I understand that Access saves the ID of the employee in the project table and that's good. However, now I want to create a search query to get all projects with e.g. Mike as responsible person.
This is my code:
SELECT projects.name, projects.responsible
FROM projects
WHERE projects.responsible = Forms!form_search!employee_name;
Now it works fine if I type in the Form the employee ID but I cannot remember all IDs. I want to be able to type in 'Mike' in the Form and the query delivers me still all of Mike's projects.
How can I achieve that?
I thought about something like:
WHERE (projects.responsible = (employees.ID WHERE employees.name = Forms...));
But this doesn't work...
You can use a dropdown list with 2 columns as a filter criteria.
To fill this list, you make a request on your employee table, hide the first column (0cm wide) and the second column would display the matching employee name but your SQL request still receive the ID as criteria.
You should NOT have to modify your SQL request.
I'm having a column "SelectedCustomers" in the database table holding selected customers that manager is editing there details NOW. For example it can contain this string '111,222,333' which means that at this current time the manager is selected to edit customers with these ids 111,222 and 333. If another manager is trying to edit a customer that already editing by the first manager the second manager should get an error, preventing him from editing this customer. This check should hold at the sql. And lets say that checking store procedure getting a nvarchard "CheckCustomers" with this value : '234,222,341'. And because the second manager is trying to edit customer with id 222 that is already selected for editing by the first manager. The second manager will get an error message. How should the sql query should be? (I have already a "split" function.)
SELECT * FROM dbo.test WHERE dbo.Split(SelectedCustomers)IN (CheckCustomers)
Why not simply add another column 'IsBeingEdited' in the customer's table? You can then simply:
SELECT id FROM customer WHERE id IN (CheckCustomers) AND IsBeingEdited = 1;
The list shows id's of customer currently being edited, right (and easily changable to other column like name)? So you can also shows that to the 2nd manager.
You can do this with CROSS APPLY.
IF EXISTS (
SELECT S.CustomerID
FROM dbo.test T
CROSS APPLY dbo.Split(T.SelectedCustomers) S
CROSS APPLY dbo.Split(T.CheckCustomers) C
WHERE S.CustomerID = C.CustomerID
)
BEGIN
RAISERROR('Customer is locked by another user', 16, 0)
END
I suggest that this design be changed. Any time do something like splitting strings to get at the 'hidden' fields inside the string is necessary it's a violation of one of the basic principles of using a relational database, which is that each field in a row should store a single value. Can this be made to work? Probably. Is it a good idea to do so? Not in my opinion.
As others have pointed out there are several ways to change the design. A column could be added to the Customer table to indicate that the customer is locked. A separate table (CustomerLocked, for example) containing the CustomerID and the manager's ID could be used - this would allow additional information to be added such as the time that the customer was locked, etc, which might be useful if someone were to lock a customer and then walk away from their desk.
I believe that either of these changes would satisfy the requirements. For example, let's say that a LockedCustomer table is created:
Table LockedCustomer
CustomerID NUMBER PRIMARY KEY
ManagerID VARCHAR
AddDate DATE
and let's say that manager A has locked customers 111, 222, and 333; thus in the LockedCustomer table the following rows would exist:
CustomerID ManagerID
111 A
222 A
333 A
Now along comes manager B, who wishes to lock customer 222. The application manager B is using attempts to insert a new row into the LockedCustomer table, as follows:
INSERT INTO LockedCustomer (CustomerID, ManagerID)
VALUES (222, 'B');
This statement should fail because CustomerID 222 already exists in the table, and the CustomerID column is the primary key on LockedCustomer. This makes sense as we only want a given CustomerID to exist at most one time in the LockedCustomer table at any point in time. The application manager B is using could then detect that the INSERT failed due to a primary key constraint violation, and would understand that this meant that the customer could not be locked at this time. By re-querying the LockedCustomer table for additional data, as in:
SELECT *
FROM LockedCustomer
WHERE CustomerID = 222
the application could present a dialog to Manager B that might look something like
The customer you wished to edit (222) is currently in use
by Manager A since 03-Jun-2011 2:17 PM. Would you like to
A) Wait
B) Send an email to Manager A
C) Take a long vacation
D) Violate company policy regarding alcohol consumption
during working hours
Please select one of the above options?
Share and enjoy.