How to use Concatenate to append strings in google sheet? - concatenation

I need to put address, city, State and postcode with space in between into one cell in google sheet.

try this:
=CONCATENATE(A1," ", B1," ", C1, " ", D1)
A1 : Address
B1 : City
C1 : State
D1 : postcode

There is a documentation that tells as how to use functions ;-)
https://www.howtogeek.com/447559/how-to-concatenate-data-from-multiple-cells-in-google-sheets/

Related

Conditional removal of rows in importhtml data output

=ARRAYFORMULA(IFERROR(
substitute(IMPORTHTML("https://niftyinvest.com/option-chain/"&D2&"?expiry="&$B$2,"Table",1),"*","")*1,
substitute(IMPORTHTML("https://niftyinvest.com/option-chain/"&D2&"?expiry="&$B$2,"Table",1),"*","")))
where D2 = MARUTI and B2 = 30Jun2022 let's say...
Now I want to remove the row in which all columns value is zero.
Try
=query(ARRAYFORMULA(IFERROR(substitute(IMPORTHTML("https://niftyinvest.com/option-chain/"&D2&"?expiry="&$B$2,"Table",1),"*",""), substitute(IMPORTHTML("https://niftyinvest.com/option-chain/"&D2&"?expiry="&$B$2,"Table",1),"",""))),
"where "&ARRAYFORMULA(TEXTJOIN(" and ",, "Col"&SEQUENCE(11,1,1,1)&" is not null")),1)
use:
=QUERY(ARRAYFORMULA(IFERROR(
SUBSTITUTE(IMPORTHTML("https://niftyinvest.com/option-chain/"&D2&"?expiry="&$B$2,"table",1),"*",)*1,
SUBSTITUTE(IMPORTHTML("https://niftyinvest.com/option-chain/"&D2&"?expiry="&$B$2,"table",1),"*",))),
"where "&TEXTJOIN(" and ", 1, "Col"&SEQUENCE(11)&" <>0"))

How to split pascal case address in SnowFlake?

In order to create PlaceKey for addresses to link some of my tables, I need to split an address column in SnowFlake.
I am not familiar with JavaScript, but I tried Javascript UDF in SnowFlake. Then I don't know how to deal with the addresses like '123_45ThSt'.
The output of my function is like '123_45 Th St'. I am stuck here.
The expected output is '123 45Th St'.
Hope someone could help me out. Much appreciated!
Below is another example and my SnowFlake SQL code:
Original address column: 12345NE17ThSt
The expected column: 12345 NE 17Th St
My function's output: 12345 NE17 ST
My function:
CREATE OR REPLACE FUNCTION Split_On_Upper_Case(s string)
RETURNS string
LANGUAGE JAVASCRIPT
AS '
function Split_On_Upper_Case(str){
str=str.split(/(?=[A-Z])/).join(" ")
return str
}
// Now call the function
return Split_On_Upper_Case(S);
'
;
Assuming the format of street address, which includes number + word (ends with lower case or number) + word (start with upper case), I have below solution:
CREATE OR REPLACE FUNCTION Split_On_Upper_Case(s string)
RETURNS string
LANGUAGE JAVASCRIPT
AS $$
regexp = /([0-9]+)(NE|SE|NW|SW)?(.*[0-9a-z]{1})([A-Z][a-zA-Z0-9]+)/g;
splits = regexp.exec(S.replace(/_/g, " "));
if (splits && splits.length == 5) {
return
splits[1].trim() + " " +
(splits[2] ? splits[2].trim() + " ": "" ) +
splits[3].trim() + " " +
splits[4].trim();
}
return "not found" // or whatever you want to do
$$;
Then try to run the function:
select Split_On_Upper_Case('12345NE17ThSt');
-- 12345 NE 17Th St
select Split_On_Upper_Case('123_45ThSt');
-- 123 45Th St
select Split_On_Upper_Case('35TestSt');
-- 35 Test St
It returns expected output, but if you have more sample inputs, they can help to validate.

Remove trailing char when congregating after merging text in multiple columns to one

I'm trying to congregate text in multiple columns into one column in google sheets. I'm using the following formula. It works but unless there is an item in column E I get a comma at the end of any entry that was in B,C, or D.
=ARRAYFORMULA(IF(ROW(G:G)=1,"Events", IF(A:A="","", B:B) & IF(B:B<>"",", "&C:C, C:C) & IF(C:C<>"",", "&D:D, D:D) & IF(D:D<>"",", "&E:E, E:E)))
How to I check to see if there are no entries after and thus remove the trailing comma.
For exmaple, this works:
event1, event2, event3, event 4
but if there is not an item in the last column (E) then it looks like this
event1, event2,
try:
=ARRAYFORMULA(REGEXREPLACE(TRIM(IF(ROW(G:G)=1, "Events",
IF(A:A="",, B:B)&
IF(B:B<>"", ", "&C:C, C:C)&
IF(C:C<>"", ", "&D:D, D:D)&
IF(D:D<>"", ", "&E:E, E:E))), ",$", ))

Case test if substring exist and replace with blank

I need to cleanup a set of companies name by replacing : INC, LTD, LTD. , INC. , others, with a empty space when they are individual words ( with one blank space before the word i.e. Incoming INC) and not letters part of company name i.e. INComing Money.
The logic I tried :
case
when FINDSTRING([Trade Name]," INC",1) > 0 then REPLACE([Trade Name]," INC","")
when FINDSTRING([Trade Name]," LTD",1) > 0 then REPLACE([Trade Name]," LTD","")
ELSE [Trade Name]
I tried SSIS expresion in a derived column :
FINDSTRING( [Trade Name] ," INC",1) ? REPLACE([Trade Name]," INC","") :
FINDSTRING([Trade Name]," LTD",1) ? REPLACE([Trade Name]," LTD",""):
The error received:
Error at Data Flow Task [Derived Column [1]]: Attempt to find the
input column named "A" failed with error code 0xC0010009. The input
column specified was not found in the input column collection.
In a similar case it is easier to use a Script Component to clean this column, you can simply split the column based on spaces then re concatenate the parts that are not equal to INC, you can use the following method to do that, or you can simple use RegEx.Replace() method to replace values based on regular expressions:
string value = "";
string[] parts = Row.TradeName.Split(' ');
foreach(string str in parts){
if(str != "INC"){
value += " " + str;
}
}
Row.outTradeName = value.TrimStart();

Ruby printing out hash data

I am working on a database that holds records for a school, where the key is the studentID, followed by the values of, first name, last name, major, and catalog year. I am working on the display function, which loops through the users which have been added to the hash. however, my code is not printing out of all the records i have added to the database.
it is only printing out one record listing, rather than my multiple inputted entries.
here is an example of input:
-----------------------------
Student Database Records
-----------------------------
1) Insert new record to database
2) Modify record in database
3) Remove record from database
4) Display record(s) in database
5) Quit
6) Enter choice:
1
-----------------------------
Add Record(s)
-----------------------------
Enter Student Identifcation Number:
32424
Enter First name of Student:
sfsdf
Enter Last name of Student:
sdfsfsf
Enter Major of Student:
sdfsdfs
Enter Catalogue Year:
sdfsfds
Your entry for Student ID 32424 has been added to the database.
------------------------------------------------------------------------
32424: sfsdf, sdfsfsf, sdfsdfs, sdfsfds
------------------------------------------------------------------------
here is my code to add an array to a hash
student_id = gets().chomp
if school_database.sDB.has_key?(student_id)
puts "Student Record Already Existent"
return school_database
end
puts "\nEnter First name of Student: "
first_name = gets().chomp
puts "\nEnter Last name of Student: "
last_name = gets().chomp
puts "\nEnter Major of Student: "
major = gets().chomp
puts "\nEnter Catalogue Year: "
catalogue_year = gets().chomp
puts "\nYour entry for Student ID #{student_id} has been added to the database.\n"
puts "\n------------------------------------------------------------------------"
puts "#{student_id}: #{first_name}, #{last_name}, #{major}, #{catalogue_year}"
puts "------------------------------------------------------------------------\n\n"
store_account_data = first_name + "," + last_name + "," + major + "," + catalogue_year
school_database.sDB[student_id] = [store_account_data]
return school_database
here is the code i am using to loop through my hash to print out the records.
school_database.sDB.each do |key, store_account_data|
puts "\n"
puts "#{key}: #{store_account_data.join(',')}"
positively, I run the .size command, and i discovered that it is adding muliple entries to the hash, however, it is not printing all of them
any ideas?
String’s + method places fairly strict requirements on what can appear on the right-hand side. You need to explicitly call to_s:
puts key + ' : ' + store_account_data.to_s
String interpolation is much more forgiving; it basically calls to_s for you:
puts "#{key} : #{store_account_data}"
Or perhaps you want a more detailed dump:
puts "#{key} : #{store_account_data.inspect}"
Or no brackets:
puts "#{key} : #{store_account_data.join(', ')}"
Or perhaps elements of store_account_data are objects, and you want to just print one property of them:
puts "#{key} : #{store_account_data.map(&:field_to_print).join(', '}"
I would do something like:
def display(database)
database.sDB.each do |key, account|
puts "#{key}: #{account.join(',')}"
end
end
You can use ruby's join method. I believe that's pretty common among languages.

Resources