MAX aggregation of rows in Webi - sap

I can't figure out how to show only example results for a field in a WebI table.
I have a data set in WebI with agents and agents' companies, among other things. The data set contains multiple companies for some agents, or with slight variations (e.g. "ACME Co." v. "ACME Company"). I want my report table to show each agent only once, with one of the values for the company next to it rather than new lines for each agent/company combination.
So the data is like:
Agent A; Company 1
Agent A; Company 2
Agent B; Company 3
Agent B; Company 4
...and I want my table to show only:
Agent A; Company 1
Agent B; Company 3
Thanks for your help.

Assuming you have no other objects in your report block that are nonunique within the Agent, you can simply use:
=[Agent]
=Max([Company])

Related

SQL - Multiple Items in Query, Multiple Results in Output, Single Records on Table

A peer reached out because he has just the employee IDs of submitters on the table he has, but needs to be able to show many documents are submitted per department. I have access to a bit more, but I can't figure out to do this. Since I don't have access to his table, he gave me the list of employee IDs. The query below doesn't give the desired result, but its as close as I come. (His list of employee IDs is also much longer.)
select wf.department, count (empid) CT from workforce wf
where wf.empid IN('1234','1234')
group by wf.department
And I'd want the result to be something like:
Department | CT
Reporting | 2
Instead, its giving a count of one, because the employee ID only appears once on the workforce table. Is there a way to count that? Even if I can just it to list the Department next to the employee IDs like the below, I can just throw into a table in Excel and get what I need manually.
Department| Empid
Reporting | 1234
Reporting | 1234
I'm using MSSMS. Any help would be greatly appreciated!
IN only does filtering. If you want to multiply the number of rows, use a JOIN:
select wf.department, count(v.empid) as CT
from (values ('1234'), ('1234')) v(empid) join
workforce wf
on wf.empid= v.empid
group by wf.department;
Note: If the values are numbers, then remove the single quotes. Try to keep the types consistent in comparisons.

VBA - Access emailing

I have a table of 1000 emails with unique identifiers and 5 other tables with matching unique identifiers. I am trying to email attachments from the first table the attachments from the remaining 5 table. one issue is that all information is store on the 5 tables. is there code I can write to "automate" the emailing without having to write thousands lines of code?
You did not provide sample data. I assume by 'emails' you mean email addresses.
Let's say the table with mail addresses is called 'accounts'. It is not clear why there are 5 other tables. Let's assume they are called a, b, c, d and e. The information in these tables is stored in field 'info'. You did not provide information on the type of database (access, mysql, postgres, oracle, ms-sql), so I am going to use as generic SQL as possible. Let's assume the id field in accounts is called 'id' and the corresponding field in the other tables is called 'accountid'. (Edit:)Let's assume the other tables do not all reference all 1000 accounts.
select accounts.email, a.info, b.info, c.info, d.info, e.info
from accounts left join a on accounts.id=a.accountid
left join b on accounts.id=b.accountid
left join c on and accounts.id=c.accountid
left join d on account.id=d.accountid
left join e on account.id=e.accountid;
Note that for some accounts some of the info fields may be empty (NULL) if the corresponding table does not have a row referencing the account.

Is there any SQL database which has a provider optimizing network communications so that columns repeated in many rows are sent only once to a client?

Considering multitude of SQL databases on the market and each having it's own providers which send the data over the wire in a custom way which means freedom of implementation, are the databases optimizing columns which values are constant for many consecutive rows so that value for a column is sent only once per group/per value change?
Since SQL engine can possibly have the information which columns will not change in the result set - why would these be sent more than once per group?
Simple example:
[Species] Table
Id GroupId Name
1 1 Goat
2 1 Horse
3 1 Donkey
4 2 Pine
[Groups] Table
Id Kingdom Description
1 Animals This is a very long description of animals group
2 Plants This is ever longer description of plants group
Now following query:
SELECT s.*, g.Kingdom, g.Description FROM Species s JOIN Groups g ON g.Id = s.GroupId
will return:
Id GroupId Name Kingdom Description
1 1 Goat Animals This is a very long description of animals group
2 1 Horse Animals This is a very long description of animals group
3 1 Donkey Animals This is a very long description of animals group
4 2 Pine Plants This is ever longer description of plants group
Implementation of such RLE-like encoding will be trivial even without going into DB engine level - just holding previous row when sending and receiving and having a "USE PREVIOUS" value pasted for one or more columns.
I got the idea for this question when I needed to join a table containing long BLOB-like field which can appear more than once in a result set; I am using Microsoft SQL Server.
My question is are there any databases doing similar optimizations in their providers? My thought was that it was always up to a user to build queries so that rows won't contain duplicate information but when multiple queries are made we have another problem of going through a whole client - server pipeline again.

MS Access 2013 - How do I select unique values from another table?

I have a database with three tables; tbl_Room, tbl_Guest and tbl_RoomGuest (a bit simplified).
`tbl_Room` has information about a certain room
`tbl_Guest` has information about a certain guest
`tbl_RoomGuest` has information about what guest stayed at which room,
and the dates they stayed.
I am making a form where I can enter information about a room, and I want to display a list of the guests that have stayed in that room.
How can I select the names from tbl_Guest, when I want to display unique names of only the guests that stayed in that room?
I want the field to be non-editable.
The query to get the unique names could be written using distinct. Here is an example:
select distinct g.GuestName
from tbl_RoomGuest as rg inner join
tbl_Guest g
on rg.GuestId = rg.GuestId
where rg.RoomId = YOURROOMIDHERE;

Query accross a circle of tables

I'm curious about how I could go about getting the data I need out of a "circle" of tables.
I have 5 tables(and a few supporting ones): 3 entities joined by junction tables. So the general model is like this:
Cards have many Budgets, and Accounts have many Budgets, and Accounts have many Cards.
So my relationships make a circle, through the junction tables, form Card to Budget to Account back to Card, This structure works all fine and dandy until today when I tried to construct a query using all 5 tables, and noticed that I know of no way to avoid abiguous joins which this structure in place. I'm thinking it might have been a better idea to create AccountBudget and CardBudget tables, but since they will both define exactly the same type of data, one table seemed more efficient.
The information I'm trying to get is basically the total budget limit for all cards of a certain type, and the total budget limit for all accounts of that same type. Am I just looking at this problem wrong?
// Card Budget_Card Budget Budget_Account Account
// ------- --------- -------- -------------- ---------
// cardId------\ budgetId<---------budgetId------>budgetId -----accountId--(to Card)->
// accountId --->cardId limit accountId<------/ typeId
// (etc) typeId (etc)
// (typeId in Budget is either 1 for an account budget or 2 for a card budget.)
As you can see, it's a circle. What I'm trying to accomplish is return one row with two columns: the sum of Budget.limit for the record in Account where typeId = 1, and the sum of Budget.limit for all rows in Card belonging to Accounts of the same type.
As per suggestion, I can in fact get the data I need from a union, but it's no use to me if the data is not in two separate columns:
SELECT DISTINCTROW Sum(Budget.limit) AS SumOfLimit
FROM (Account RIGHT JOIN Card ON Account.accountId = Card.accountId)
RIGHT JOIN (Budget LEFT JOIN Budget_Card ON Budget.budgetID = Budget_Card.budgetId) ON Card.cardId = Budget_Card.cardId
GROUP BY Budget.typeId, Budget.quarterId, Account.typeId
HAVING (((Budget.typeId)=2) AND ((Budget.quarterId)=[#quarterId]) AND ((Account.typeId)=[#accountType]))
UNION SELECT DISTINCTROW Sum(Budget.limit) AS SumOfLimit
FROM Budget LEFT JOIN (Account RIGHT JOIN Budget_Account ON Account.accountId = Budget_Account.accountId) ON Budget.budgetID = Budget_Account.budgetId
GROUP BY Budget.typeId, Budget.quarterId, Account.typeId
HAVING (((Budget.typeId)=1) AND ((Budget.quarterId)=[#quarterId]) AND ((Account.typeId)=[#accountType]));
So, if I understand you correctly, you've made separate column headers with the same name, and so your data becomes skewed because the information needs to be separated? If this is the case I would suggest changing the column headers as you've proposed, or in linking two queries together. To connect the data by querying the same tagged name will combine results. If you want to designate something, it's always a good idea to create separate names for column headers.
Here is an explanation of using SQL to query multiple tables: http://www.techrepublic.com/article/sql-basics-query-multiple-tables/1050307
First make the query for the Cards, then union with the query for the Accounts
Although it would be easier to relate cards to accounts and then only have budgets for accounts, however i don't know if that would work with your schema