Split content of field into 2 fields [duplicate] - sql

This question already has answers here:
sql create a field from a field
(4 answers)
Closed 9 years ago.
I have to run a query in Access sql or using the Query Wizard to split the data of field into 2.
The field has data such as 1234 ave willie and has email addresses such as haha#yahoo.com .
I need to put 1234 ave willie in a new field named St address and haha#yahoo.com in Email.
Can someone help? Is there a wildcard operator like LIKE etc?

You should look into using LIKE to determine which field is an email and which field is an address. Something like this would work:
SELECT Field, 'Email' FieldType
FROM YourTable
WHERE Field Like '*#*'
UNION ALL
SELECT Field, 'Address' FieldType
FROM YourTable
WHERE Field Not Like '*#*'
You mention you need to split these in 2 separate fields -- depends on the table structure. But assuming you add 2 new fields to the original table, then something like this should work:
UPDATE YourTable SET Email = Field WHERE Field Like '*#*'
UPDATE YourTable SET Address = Field WHERE Field Not Like '*#*'
You can find a better algorithm to search by email address -- this is just an example. But assuming any field with an # symbol is an email, then the above will work fine. Here's an SO post with SQL Email validation that can help get you started:
Sql script to find invalid email addresses

Related

Remove Phone Numbers & Email Addresses in a string SQL

I have a Table with Field "UserId" in Postgres
The List Contains a list of UserIds (comma separated) but also might contain email addresses and phone numbers .
Example
ID
UserID
1
11111,22222,+9199999999,xyz#yxz.com
3
2222,3333,11,+887777777,abc#bca.com
I want to remove all the phone-numbers and Email addresses and get the list of all userids comma separated in a new field.
OUPUT
ID
UserID
1
11111,22222
3
2222,3333,11
Also it will be better to have the query being optimised as it will be a part of a much complex query and should not not impact the performance .
Can someone suggest an ideal way to do it ?
Thanks
I have tried SUBSTRING , SPLITPART and Case Conditions based on it , but couldn't come out with a proper solution.
Use the REGEXP_REPLACE function to remove phone numbers.
UPDATE tablename SET columnname = REGEXP_REPLACE(columnname, '(\+[0-9]{1,3}[- ]?)?[0-9]{10,}', '');
Use the REGEXP_REPLACE function to remove email addresses.
UPDATE tablename SET columnname = REGEXP_REPLACE(columnname, '[A-Z0-9._%+-]+#[A-Z0-9.-]+\.[A-Z]{2,}', '');

How would I select a specific number of characters in between a string in Google big query?

I have a field in my BQ table which is of type string and I need to select some characters in between them.
What I have:
student_details is the table, and details is the only field in the table and is of type STRING.
details
name:rishi;id=32a01a-2tf5-433a-7117-12323adfr2;dept:maths
name:vineeth;id=83faf-34fa-9912-afd-dsfeffef13fd;dept:science
I need only id in a separate field.
what I want:
(Basically I want characters after id= and before ;dept)
details id
name:rishi;id=32a01a-2tf5-433a-7117-12323adfr2;dept:maths 32a01a-2tf5-433a-7117-12323adfr2
name:vineeth;id=83faf-34fa-9912-afd-dsfeffef13fd;dept:science 83faf-34fa-9912-afd-dsfeffef13fd
Could anyone please help me on this.
You can use regexp_extract():
select regexp_extract(details, ';id=([^;]+);') as id

split string with specific character

Here is my situation
there is a column that comes from csv file, i loaded all fields properly in sql but in email column, i have more than 1 email address for some records.
if it would be 2 emails, i could handle but as long as i have 3-4 or more emails, then i have little problem.
here is an example
'ekuntsche#addictionsuisse.ch;ekuntsche#suchtschweiz.ch;ekuntsche#sfa-ispa.ch;ekuntsche#addiction-info.ch'
this is only 1 column, i need to split them to 4 different column as email1,email2,email3,email4 and delimiter is ';'
I think i should use charindex and substring etc. but i could not create it.
if someone can create a function and show how to run the function, that would be super helpful.
thank you
database name 'bi_deploy'
main column name is 'email'
unique id for this table is 'ID'
(this is only email table, every row will have 1 email address, i can make it actually, but i could not split emails properly)

like within query

I am using vs 2010 and want to perform a query on sql server database. But i have a problem i want to retrieves a row on the basis of name which i want to retrieves it using second character of name that is i don't know the first character that is for example the name is nik as i enter i it will retrives a record which having nik as value of name column.
Can any one guided me...I know following query what things i have to modified in it.
select * from table1 where name like '"& n % &"'
for example the name is nik as I enter i it will retrives a record which having nik as value of name column
try
select * from table1 where name like '_i%'
TSQL Like

Simple sql query problem

Hi I have this query in ms access which is somehow not working. All I need to do is to pull out donator name from donator table with the id of volunteer. But I need to get user input, volunteer name and pull out the related volunteer first. Please help.
SELECT volunteer.id, volunteer.name, donator.* FROM volunteer, donator WHERE Volunteer.id = Donator.vid AND Volunteer.name = Forms!frm5!Combo2;
Check your case on Database names. For instance, you reference volunteer.name and Volunteer.id. In some DB's, fields are case sensitive.
Also, you'd want to quote your volunteer name field.