Announcement

Collapse
No announcement yet.

Implizite sortierung

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Implizite sortierung

    Folgende Funktion soll einen String anhand eines spearators zerlegen und die ergebnisse zurückgeben(als tabelle) schreiben. Wieso werden aber die ergebnisse sortiert?? Es ist doch ein simples insert!!

    CREATE FUNCTION FHELP_SplitString(@String VARCHAR(8000), @Separator VARCHAR(8000))
    RETURNS @OutPut TABLE(Value VARCHAR(8000))
    AS
    BEGIN
    DECLARE @SeparatorLength INT,
    @StartLocation INT,
    @EndLocation INT

    SELECT @SeparatorLength = LEN(@Separator), @StartLocation = 0,
    @EndLocation = CHARINDEX(@Separator, @String)

    IF @String = '' SET @String = NULL
    IF ISNULL(@EndLocation, 0) = 0
    SELECT @EndLocation = LEN(@String) + 1

    WHILE ISNULL(@EndLocation, 0) > @StartLocation BEGIN
    INSERT INTO @OutPut(Value) VALUES (RTRIM(LTRIM(SUBSTRING(@String, @StartLocation, @EndLocation-@StartLocation))))

    SELECT @StartLocation = @EndLocation + @SeparatorLength,
    @EndLocation = CHARINDEX(@Separator, @String, @StartLocation)

    IF ISNULL(@EndLocation, 0) = 0
    SELECT @EndLocation = LEN(@String) + 1
    END

    RETURN
    END

  • #2
    Hallo!

    Sql ist mengenorientiert...

    Erweitere die Tablle um die Startlocation, dann kannst die Reihenfolge mit order by StartLocation sicherstellen...

    BYE BERND

    Comment


    • #3
      Danke, das hat geholfen

      Comment

      Working...
      X