2
I have an appointment of SQL
that the content brings me so:
[email protected];[email protected]
I only need the first address, I have to disregard everything from the ;
?
2
I have an appointment of SQL
that the content brings me so:
[email protected];[email protected]
I only need the first address, I have to disregard everything from the ;
?
2
If you go directly to SQL
use a function junction, SUBSTRING and CHARINDEX:
SELECT SUBSTRING(email, 1,CHARINDEX(';', email)-1) from emails;
where email
is the field that holds electronic addresses separated by comma and emails
the table name.
Withdrawn response: Soen - How to split a comma-separated value to Columns
A suitability to pick up emails that have no items separated by ;
, ie only an email contained in the field without ;
:
select CASE WHEN Charindex(';', email)>0
THEN Substring(email, 1,Charindex(';', email)-1) ELSE
email END
from emails
References:
I believe this response is more appropriate
1
There are some ways:
indexed
String result = "[email protected];[email protected]";
int index = result.indexOf(";");
if (index > 0) {
result = result.substring(0, index);
}
System.out.println(result);
split
String result = "[email protected];[email protected]";
String[] emails = result.split(";");
result = emails[0];
System.out.println(result);
Thanks for the help.
1
You can use the Java split function to do this.
String email = "[email protected];[email protected]";
String[] emails = email.split(";");
System.out.println(emails[0]);
The split function divides a String into several Strings using the given delimiter and returns the parts in a String vector. Since you only need the first, just use:
emails[0]
See working on ideone.
Thanks for the help.
Browser other questions tagged java sql-server string sql-server-2005
You are not signed in. Login or sign up in order to post.
Which bank?
– novic
SQL Server, the application always worked, when only one email was registered in the customer’s database, now invented of for one more and gave problem
– RenanPontes
Sorry about the version?
– novic
What version of the Bank, @Renanpontes?
– novic
SQL Server Standard 2005, but I will treat after the same query.
– RenanPontes
Note the best test option maybe it pays to do the way I implemented, maybe not, but first of all test...
– novic