2

I want to split values based on multiple values like ',' & 'And', operators. But I used 'And' in split function it is not working, can someone help me to achieve this?

select distinct y.value from  history x
 cross apply STRING_SPLIT(x.query, ',') y 
where lower(rtrim(ltrim(y.value))) not in (
    select s.value from keys s cross apply STRING_SPLIT(y.value, 'And') z where lower((s.value)) like lower(rtrim(ltrim(z.value)))
);

Msg 214, Level 16, State 11, Line 23 Procedure expects parameter 'separator' of type 'nchar(1)/nvarchar(1)'.

Sample input Data:

student,teacher,tutor and principle and director

Output:

student
teacher
tutor
principle
director
4
  • Please include some sample data. There might another way to go about doing this. Commented May 3, 2019 at 1:19
  • updated with sample data Commented May 3, 2019 at 1:24
  • 4
    If "and" is the only word that is present in your input, then simply do a replace of And with a comma and then do a string split Commented May 3, 2019 at 1:27
  • @Harry That sounds like a good answer to me :-) Commented May 3, 2019 at 1:33

1 Answer 1

4

If "and" is the only word that is present in your input, then simply do a replace of And with a comma and then do a string split

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.