Need to delete a substring in one column if equal to string in another - sql-update

I have a table with street and city fields however most street fields have the city listed in it as well at the end. I have identified those records but now would like to delete the city from the street. Here is the query that I used to identify bad records. I am just learning SQL and would appreciate any help.
SELECT *
FROM mytable
WHERE Mailing_Street like CONCAT('%',SUBSTRING(mailing_city,1,Len(mailing_city)))
I am looking for
street
123 Main St Anytown
to be updated to
street
123 Main St
where city = Anytown

Related

Power BI How to remove duplicate rows?

In my report view, I have a table where the rows are repeated twice => once for each position available. I want to show only one row for each employee with his latest position. How can I accomplish this?
Name
Project
Date
Position
John Smith
PowerProject
01-01-2021
Engineer
John Smith
PowerProject
01-01-2021
Senior Engineer
Sort on the date. Group on the name. Choose All Rows as the function and change the code from _ to Table.Last(_) then expand

in PowerBI - How to group a table by a column, and return all unique values (coma seperated) from another column as grouped

I am trying to group a table by a column, so the resulted table have unique values in that column, and also returns all the unique values from another column that belonged to the grouped column:
Source:
Country = USA
Cities =
New York
Boston
Chicago
Houston
Transform: group by [Country] column, and return unqiue values from [Cities] and coma seperated:
Country = USA
Cities = New York,Boston,Chicago,Houston
thanks a lot
You can simply use CONCATENATEX in a measure
Measure = CONCATENATEX(VALUES('Table'[Cities]),'Table'[Cities],",")

How to filter a table for distinct values Powerapps

I am new to Powerapps and I have noticed that the Distinct function returns a table of the distinct values(only returns the distinct column not the full row). Is there a way to filter a table so that it returns back a subset of the full table with distinct values in a specified column.
You can use the GroupBy function for this. Take a look at the documentation, or in the example below:
Assuming that cities is a table with the following values:
City
Country
Population
London
UK
8615000
Berlin
Germany
3562000
Madrid
Spain
3165000
Rome
Italy
2874000
Paris
France
2273000
Hamburg
Germany
1760000
Barcelona
Spain
1602000
Munich
Germany
1494000
Milan
Italy
1344000
The expression GroupBy(cities, "Country", "Cities") will return a table with a column "Country", and a column called "Cities" whose value will be a table with all cities for that country.
You can then use functions such as AddColumns and Sum to aggregate the values of the inner table, like in the example below:
AddColumns(
GroupBy(cities, "Country", "Cities"),
"Sum of City Populations",
Sum(Cities, Population))
In your tweets example, if you want to get one tweet from each day, you can have an expression like the one below:
AddColumns(
GroupBy(Tweets, "crf1d_date_index", "Dates"),
"SampleTweet",
First(Dates))
Where it would have a new column with the first tweet from each date. Or if you want a single field from the group, you can have something like this:
AddColumns(
GroupBy(Tweets, "crf1d_date_index", "Dates"),
"FirstTweetTime",
First(Dates).tweet_time)

Calculate Total male Total Female in powerbi report

I want to count the total number of males and females in a powerbi report
eg.
Name Gender
std1 Female
std2 Male
std3 Female
std4 Male
std5 Male
std6 Male
The result I want is:
Female 2
Male 4
To get the results you are looking for, follow these steps:
Make a second table using the New Table button with the following code:
GenderCounts = DISTINCT(TableName[Gender])
Make a relationship from the newly create table back to the original table
Add a new column to the GenderCounts table with the following code:
Count = COUNTROWS(RELATEDTABLE(TableName))
And there you have a second table containing the counts of each gender.
For more information and other possibilities, check out a related Power BI Community forum post here and Stackoverflow questions here and here.

Informatica Powercenter One to Many SQ Query and Mapping Issues

I have multiple VIEWs where the PERSON_VIEW to a PHONE_VIEW has a one to many relationship. In the following query, I got TOAD to correctly output the result into 1 row for each person record.
I am having a problem getting it to work with Informatica Powercenter. I copied/pasted the query to SQ SQL Query section.
Since the query takes the PHONE_NUMBER and check against the PHONE_TYPE on whether it is of type HOME, BUSINESS, or PERSONAL, it output 3 phone number columns called HOME, BUSINESS, and PERSONAL.
I created 3 new columns in the SQ Ports called HOME, BUSINESS, and PERSONAL to match the query output columns. When I validate the query, it constantly says it must match 28 ports from the SQ. When I just add 1 column and map to Exp Transformation and then to the Target, it still give this error. I counted the ports and it is 29. If I removed the phone columns, it works and the count is 28. When I add just one phone column, it gives the error.
I think I am missing a step.
Any help is appreciated.
PERSON VIEW
1 John M. Doe
PHONE VIEW
1 111-111-1111 HOME
1 222-222-2222 BUSINESS
1 333-333-3333 WORK
TOAD Result
1 John M. Doe 111-111-1111 222-222-2222 333-333-3333
Here is the QUERY (This works in TOAD)
SELECT PERSON.PERSON_ID,
PERSON.FIRST_NAME,
PERSON.MIDDLE_NAME,
PERSON.LAST_NAME,
PHONE.HOME,
PHONE.BUSINESS,
PHONE.PERSONAL,
PHONE_TYPE
FROM PERSON_VIEW PERSON
LEFT JOIN (SELECT * FROM (SELECT PERSON_ID, PHONE_TYPE,PHONE_NUMBER
FROM PHONE_VIEW)
PIVOT
(
MAX(PHONE_NUMBER)
FOR PHONE_TYPE in ('HOME' AS HOME,'PERSONAL' AS PERSONAL , 'BUSINESS' AS BUSINESS)
)
)PHONE ON PHONE.PERSON_ID = PERSON.PERSON_ID