I have data that looks similar to this:
TaskID | Email_To |
---|---|
1 | @Email.org.uk; |
2 | @Email.org.uk; @Email.org.uk; |
3 | @Email.org.uk |
In the Email_To column, there can be multiple individuals that certain tasks email to. The individuals are split up by the ";". However, there is inconsistent use of the semicolon. Some tasks with only one email_to use the semicolon and some do not.
Would there be a way to identify only those tasks that email to individuals?
CodePudding user response:
If you always (or could) have a semicolon (;
) at the end, you could TRIM
those first, and then check if the character is in the string. This assumes you are using a fully supported version of SQL Server, due to the omission of contrary information:
SELECT Task_ID,
Email_To
FROM dbo.YourTable
WHERE TRIM(';' FROM Email_To) LIKE '%;%';
CodePudding user response:
You can check if the first semicolon is the last char in a string or missing at all
select *
from tbl
where where charindex(';', Email_To) in (0, len(Email_To));