I couldn't make the title clearer, but here's what I need help with.
I have a custom page type [1] for Leaders which includes 2 fields: Name, and Title. This holds the list of all leaders at the company.
I have another custom page type [2] for Speaking Events, which includes a field called Speaker to display the speaker's name and title. This field was set up as a drop-down list with data source from a SQL Query to query the Leaders data in [1].
Select LeadersID, Name, Title from co_leaders order by Name
I got it work fine - the drop-down displays a list of Name. However, what I wanted to display in the drop-down option is: Name, Title (not just Name) like below so that I only pick one and have both Name and Title. Is it possible to do this?
John Doe, CEO
Jane Doe, CFO
Hope it's clear and thanks for your input!
This is the SQL you are looking for:
SELECT LeadersID, Name + ', ' + Title FROM co_leaders ORDER BY Name
You need to do a concatenation of the column values (Name and Title), as opposed to selecting the columns separately.
EDIT: This is assuming that Name and Title are not nullable fields.
If there is a NULL value in any of the concatenated fields, the end value will be NULL. In this case, you will need to use COALESCE (or an equivalent function) to define an alternative value. For example:
SELECT LeadersID, Name + ', ' + COALESCE(Title, 'Member') FROM co_leaders ORDER BY Name
Related
I have 3 free-text custom fields on inventory item record. they contain different information based on location so my fields names are "XXXX Location1", "XXXX Location2" and "XXXX Location3". Across all transactions in the system we need to populate the information in a custom column field of these 3 fields based on the main location we choose on that transaction.
For example if on an Invoice the Main location is Location1 then our line custom column field should show information from "XXXX Location1" when user choose that item on the line; if Main location is Location2 on that Invoice then the line custom column field should show information from "XXXX Location2" when select that item on the line.
I understand this needs to be done thru scripts but i don't know how to write the script, could someone help?
Appreciate!!!
You don't need a script for that.
On the colmn field, set the field to be a formula.
In the formula, write the followin statement(change to real location names and real item custom field ids):
Case {location}
When "location1 name" then {item.custitem... }
When "location2 name" then {item.custitem.. }
When "location3 name" then {item.custitem...}
End
I need to strip records to show just the most recent for a given person, and I'm trying to think of a method for doing this in a custom column so I can just keep the most recent records. This is essentially a a status change list, and I need to match the last change as a "current status" for merging with another query. Each date can be unique, and each person can have any from 1 to a dozen status changes. I've picked a selection below, Last Names have been removed to protect the innocent. For sake of the example, Each "name" has a unique identifier that I can use to prevent any overlap from similar names.
AaronS 4/1/2015
AaronS 10/16/2013
AaronS 5/15/2013
AdamS 2/27/2007
AdamL 12/16/2004
AdamL 11/17/2004
AlanG 11/1/2007
AlexanderJ 7/1/2016
AlexanderJ 1/25/2016
AlexanderJ 4/1/2015
AlexanderJ 10/16/2013
AlexanderJ 6/1/2013
AlexanderJ 11/7/2011
My goal would be to return the most recent date for each individual "name" and nulls for the other rows. Then I can filter out nulls to return one row per name. I'm fairly new to power query and mostly adept with the UI, barely learning M Code. Any help will be most welcome.
GUI
Bring the "Name" and "Date" data into Power Query.
Group by "Name". In the Group By dialog select the operation All Rows. Name the new column "AllRows". Click OK.
Add a custom column and title it "LatestRow". Enter the formula below. Click OK. Note that the "Date" column is coming from the sub-table in the "AllRows" column.
= Table.Max([AllRows], "Date")
Click the expand button in the upper right corner of the "LatestRow" column. This will return the record associated with the latest date for each name.
Code
let
Source = Excel.CurrentWorkbook(){[Name="data"]}[Content],
GroupedRows = Table.Group(Source, {"Name"}, {{"AllRows", each _, type table [Name=nullable text, Date=nullable datetime]}}),
AddedCustomColumn = Table.AddColumn(GroupedRows, "LatestRow", each Table.Max([AllRows], "Date")),
ExpandedLatestRow = Table.ExpandRecordColumn(AddedCustomColumn, "LatestRow", {"Date"}, {"LatestRow.Date"})
in
ExpandedLatestRow
All I've done a lot of background reading on this on and off for the past day or so and I'm none the wiser on how to achieve this.
I have looked on this site and found ways of concatenating multiple rows into one column however what I'm after is a bit more bespoke, please help...
I have two tables - one is a list of people and details about them such as name etc and a person reference.
The second contains a number of alerts about a person, one person can have multiple alerts. This would contain a person reference and the type of alert they have in a string.
I want to join these two tables using an inner join on the person reference.
I next want to find all of the alerts for each person and concatenate it into a string and show this as the "All alerts" column.
So I will end up with the following output:
First Name | Surname | All Alerts
-----------+---------+--------------------------
Tony | Stark | Alert 1, Alert 2, Alert 3
I can get as far as going through all of the alerts in the alerts table and put the alerts for every person into a string, obviously I need a concatenated value for each person, and haven't figured out how to do this.
I've spent a day on this and looked into XMLPath solutions and using CTE, CROSS APPLY and subqueries to specify the where clause. I am a little lost.
DECLARE #ConcatenatedVals VARCHAR (255)
SET #ConcatenatedVals =
(
DECLARE #AllAlerts VARCHAR(8000)
SELECT #AllAlerts = COALESCE(#AllAlerts + ', ', '') + personAlert
FROM Alerts
SELECT #AllAlerts AS 'All Alerts'
)
I found the solution for this posted here:
https://www.simple-talk.com/sql/t-sql-programming/concatenating-row-values-in-transact-sql/#Toc205129480
This referenced a solution by Adam Machanic
Also, stuff is actually a function, not seen this before:
SELECT p1.CategoryId,
stuff( (SELECT ','+ProductName
FROM Northwind.dbo.Products p2
WHERE p2.CategoryId = p1.CategoryId
ORDER BY ProductName
FOR XML PATH(''), TYPE).value('.', 'varchar(max)')
,1,1,'')
AS Products
FROM Northwind.dbo.Products p1
GROUP BY CategoryId ;
I am very new to lotus notes. This will all be done on the client. I need to write a custom search that will search a particular form. This an example of the fields:
FormName = MyForm1
database fields are called Name1, Name2, Name3
datasbase fields are department1, deparment2, department3, department 4.
The search form will only have 2 fields. Name and Department. I need the following to happen, The name search field needs to seach all 3 name fields, the department field needs to search all 4 department fields.
Thank you for your assistance.
It depends a bit on exactly how fuzzy you need your search to be. Are you searching for an exact match, or for a partial match in those fields?
Assuming the exact match, you just need a formula that looks in the multiple name fields, and multiple department fields for a match. Let's call the search query fields NameQuery and DepartmentQuery. Then you could construct this formula which would return true if the value in NameQuery is found within one of the name fields, and the value in DepartmentQuery is found in one of the department fields.
#IsMember(NameQuery; Name1:Name2:Name3) & #IsMember(DepartmentQuery; Department1:Department2:Department3:Department4);
If instead you need to search for a partial match, you could use the #LIKE formula. First, concatenate the name and department field values into a single string using #IMPLODE. You can then do a wildcard match. This isn't very efficient, mind you, so if you're working on tens of thousands of documents you might want to find a better solution.
AllNameItems := #Implode(Name1:Name2:Name3; " ");
AllDepartmentItems := #Implode(Department1:Department2:Department3:Department4; " ");
#Like(AllNameItems; "%" + NameQuery + "%") & #Like(AllDepartmentItems; "%" + DepartmentQuery + "%");
Mike --
The built-in search will work fine for you, no doubt!
Here are the steps...
- Build your new form (ie, "MyForm" ) to hold your data;
- Build your view, to display your data as columns;
- Set your view's "Form Formula" to "MyForm" (with quotes)
- Make sure the "search bar", is enabled, for the view;
- Enter the values to search for;
- The results are displayed, nicely!
That should help...
I have predefined item combination (for example brand1|brand2|brand3 etc) in the table.
i like to collect brands and check against with predefined table data.
For example i collected brand1|brand2|brand3 then i can do get some value form that predefined table(it meets the condition).
How can i check?
brands would be unlimited. also brand1|brand2|brand3 of brand1|brand2| exist then returns true.
Okay, taking a wild guess at what you're asking, you have a delimited field with brands in them separated by a | character. You want to return any row that has the right combination of the brands in there, but don't want to return rows with, for example, brand "testify" in them when you search for "test".
You have four search conditions (looking for brand3):
the brand exists by itself: "brand3"
the brand starts the delimited field: "brand3|brand4|brand6"
the brand is in the middle of the field: "brand1|brand3|brand6"
the brand is at the end of the field: "brand1|brand2|brand3"
so, in SQL:
SELECT *
FROM MyTable
WHERE BrandField = 'brand3'
OR BrandField LIKE 'brand3|%'
OR BrandField LIKE '%|brand3|%'
OR BrandField LIKE '%|brand3'
Repeat as required for multiple brands.