October 30, 2018 at 8:49 am
Krasavita - Tuesday, October 30, 2018 8:28 AMYes separate line for this particular case, I think string_split need to be used by I don' know how.
My code:
SELECT
CASE
--need help here-
WHEN a.[Person Email] like '@rs.org
%'THEN
LTRIM(RTRIM(STRING_SPLIT.a.[Person Email].value(' ', 'VARCHAR(100)'))) --- I need help here
WHEN a.[Person Email] LIKE '%@rs.iorg%' THEN REPLACE([Person Email] , '@rs.iorg', 'rs.org')
WHEN a.[Person Email] LIKE '%.uF%' THEN REPLACE(REPLACE([Person Email] , '.uF', ''), '', '')
WHEN a.[Person Email] LIKE '%@xs.org%' THEN REPLACE([Person Email] , '@xs.org', '@rs.org')
ELSE
a.[Person Email]
END AS [Person Email],
a.[Person Email] AS [Person Email_old]FROM R1_Person_10032018
You have been on this site for 10 years, you know what is needed to provide you with better answers and tested code. Please post working DDL, sample data, expected results in a readily consumable format.
October 30, 2018 at 8:56 am
here is sample data
October 30, 2018 at 9:00 am
Krasavita - Tuesday, October 30, 2018 8:56 AMhere is sample data
Where?
October 30, 2018 at 9:24 am
data was posted sorry
October 30, 2018 at 9:46 am
Krasavita - Tuesday, October 30, 2018 9:24 AMdata was posted sorry
Obviously you don't know what readily consumable data is. Please read the following: http://www.sqlservercentral.com/articles/Best+Practices/61537/
October 30, 2018 at 9:48 am
Nobody's going to download files that can damage his computer. Can you just post the contents of the spreadsheet here?
October 30, 2018 at 10:45 am
October 30, 2018 at 10:52 am
SELECT [Person Email_old], T.CleanedPersonEmailold, LEFT(T.CleanedPersonEmailold,CHARINDEX(' ',T.CleanedPersonEmailold)-1) SingleEmail
FROM Person_oldemail
CROSS APPLY(VALUES (REPLACE(REPLACE(REPLACE([Person Email_old],CHAR(13),' '),CHAR(10),' '),'"','')+' ')) T(CleanedPersonEmailold)
October 30, 2018 at 10:59 am
Krasavita - Thursday, October 25, 2018 10:24 AMHelloHOw can I separate this data
I have buch of emails in a row, I need to keep just one and remove the rest
example:"angelina.uhi@ors.org oladi.ade@ors.org"
Result should be just 1 email:
Thank you
Which e-mail? does it matter? Use DelimitedSplit8K SELECT oe.[Person Email_old]
, e.Item
, e.ItemNumber
FROM Person_oldemail oe
CROSS APPLY Scratchpad.dbo.DelimitedSplit8K(oe.[Person Email_old],' ') e
WHERE e.ItemNumber = 1;
October 30, 2018 at 11:33 am
October 30, 2018 at 11:41 am
Here is Krasavita's code formatted using SQLPrompt, so my be easier to read:
select 'DSPN' = ltrim(rtrim([SPLIT].[a].[value]('.', 'VARCHAR(100)')))
, 'DSPN_old' = [a].[DSPN]
, [a].[DSPNXML]
, [a].[Region]
, [a].[Country]
, 'Person Name' = case
when [Person Name] like '"%"' then
replace(replace([Person Name], '"', ''), '', '')
else
[person name]
end
, 'PersonName_old' = [a].[Person Name]
, 'Person Email' = case
when [a].[Person Email] like '%@crs.org %'
or [a].[Person Email] like '"%"' then
replace(left([Person Email], charindex(' ', [Person Email]) - 1), '"', '')
when [a].[Person Email] like '%@crs.iorg%' then
replace([Person Email], '@crs.iorg', '@crs.org')
when [a].[Person Email] like '%@xrs.org%' then
replace([Person Email], '@xrs.org', '@crs.org')
else
[a].[Person Email]
end
, 'Person Email_old' = [a].[Person Email]
, [a].[Country Program]
from
(
select 'DSPNXML' = cast('<M>' + replace([Corrected_DSPN], '|', '</M><M>') + '</M>' as xml)
, *
from
(
select case
when [DSPN] like ('[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]') then
[DSPN]
when [DSPN] like ('[0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9][0-9][0-9][0-9]') then
replace([DSPN], '-', '')
when [DSPN] like ('[0-9][0-9][0-9][0-9].[0-9][0-9][0-9].[0-9][0-9][0-9][0-9]') then
replace([DSPN], '.', '')
when [DSPN] like ('[0-9][0-9][0-9][0-9] [0-9][0-9][0-9][0-9][0-9][0-9][0-9]') then
replace([DSPN], ' ', '')
when [DSPN] like ('[0-9][0-9][0-9][0-9].[0-9][0-9][0-9][0-9][0-9][0-9][0-9]') then
replace([DSPN], '.', '')
when [DSPN] like ('[0-9][0-9][0-9][0-9]- [0-9][0-9][0-9][0-9][0-9][0-9][0-9]') then
replace([DSPN], '- .', '')
when [DSPN] like ('%[0-9]%[_;]%[0-9]%') then
[translate](replace([DSPN], ' ', ''), '_;', '||')
when 'dspn' like ('%[0-9]% %[0-9]%') then
case
when [DSPN] like '"%"' then
replace(replace([DSPN], '"', ''), ' ', '|')
when [DSPN] like '%-%' then
replace(replace([DSPN], '-', '|'), ' ', '')
else
replace(
replace(
replace(replace(replace([DSPN], '.', ''), ',', ''), ' ', '|')
, '||'
, '|'
)
, '||'
, '|'
)
end
when [DSPN] like ('%[a-z]%') then
''
when len([DSPN]) <= 11 then
null
when 'DSPN' like ('%/%') then
replace([DSPN], '/', '|')
when [DSPN] is null then
''
else
'0'
end Corrected_DSPN
, *
from R1_Person_10032018
) tst
) a
cross apply DSPNXML.nodes('/M') as split(a);
October 30, 2018 at 6:20 pm
Ya just gotta wonder if all those CASEd LIKEs are slower than just doing unconditional REPLACEs with the right collation.
p.s. Apparently the version of SQLPrompt you used doesn't know what the TRANSLATE function is in 2017.
--Jeff Moden
Change is inevitable... Change for the better is not.
October 30, 2018 at 10:36 pm
Jeff Moden - Tuesday, October 30, 2018 6:20 PMYa just gotta wonder if all those CASEd LIKEs are slower than just doing unconditional REPLACEs with the right collation.p.s. Apparently the version of SQLPrompt you used doesn't know what the TRANSLATE function is in 2017.
SQLPrompt won't change code that way. All it did was format the code that was written. Easier to read than what was originally posted.
October 31, 2018 at 6:06 am
Lynn Pettis - Tuesday, October 30, 2018 10:36 PMJeff Moden - Tuesday, October 30, 2018 6:20 PMYa just gotta wonder if all those CASEd LIKEs are slower than just doing unconditional REPLACEs with the right collation.p.s. Apparently the version of SQLPrompt you used doesn't know what the TRANSLATE function is in 2017.
SQLPrompt won't change code that way. All it did was format the code that was written. Easier to read than what was originally posted.
But it did. It put brackets around the word TRANSLATE.
--Jeff Moden
Change is inevitable... Change for the better is not.
October 31, 2018 at 8:31 am
Jeff Moden - Wednesday, October 31, 2018 6:06 AMLynn Pettis - Tuesday, October 30, 2018 10:36 PMJeff Moden - Tuesday, October 30, 2018 6:20 PMYa just gotta wonder if all those CASEd LIKEs are slower than just doing unconditional REPLACEs with the right collation.p.s. Apparently the version of SQLPrompt you used doesn't know what the TRANSLATE function is in 2017.
SQLPrompt won't change code that way. All it did was format the code that was written. Easier to read than what was originally posted.
But it did. It put brackets around the word TRANSLATE.
Oh, I see. I am running an older version of SQLPrompt. Company would not renew the Toolbelt Essentials license. I thought you were talking about actually changing the code to use TRANSLATE. I should have looked closer. Sorry.
Viewing 15 posts - 16 through 30 (of 42 total)
You must be logged in to reply to this topic. Login to reply