Substring of a SQL Server txt

0

I'm trying to stay with only the part that says yes of the string:

  

'C: \ Direction \ Other \ No \ No \ Yes \ Yes \ Yes \ Yes'

The idea is that in the end I stayed:

campo 1 | campo 2 | campo 3 | campo 4 | campo 5
  algo  |   yes   |   yes   |   yes   |   yes

What he says would not rule him out and what he says would go in different fields.

Now, are they different substrings? Or do I have to use a regular expression?

My query is about SQL Server

    
asked by jqc 23.08.2018 в 18:01
source

1 answer

0

If I did not understand your question, it would occur to me that you first make a split by the "\" sign, then you sweep this array of results and before sending them to save if the data == 'Yes' you store it, Otherwise you discard it.

It would be something like this: (     @Text VARCHAR (MAX),     @DELimitator CHAR (1) ) RETURNS @output TABLE (Data VARCHAR (MAX) ) BEGIN     DECLARE @Start INT, @Terminate INT     SELECT @Empieza = 1, @ Termina = CHARINDEX (@Delimitador, @Texto)     WHILE @Empieza < LEN (@Texto) + 1 BEGIN         IF @Termina = 0
            SET @Termina = LEN (@Texto) + 1

    INSERT INTO @output (Datos)  
    VALUES(SUBSTRING(@Texto , @Empieza , @Termina - @Empieza ))
    SET @Empieza = @Termina + 1
    SET @Termina = CHARINDEX(@Delimitador , @Texto , @Empieza )

END
RETURN

END

    
answered by 23.08.2018 в 19:09