ich eine Tabelle Variable vom Typ erhalten wie dieseEntfernen Sie einige Zeichen einer Spalte aus einer Tabelle Variable vom Typ
color
-------------
Black
Blue<br/>PMS 285C
Green<br/>PMS 360
Red<br/>PMS 199
Ich möchte sie wie
color
-------------
Black, Blue, Green, Red
Aber ich eine sehr schwierige Zeit habe machen um den "& lt .." Zeug zu entfernen. folgte ich diese Antwort: Is there a way to loop through a table variable in TSQL without using a cursor? Um eine temporäre Tabelle in einer Schleife zu erstellen und die Zeichen entfernen, aber immer noch nicht
DECLARE @result int, @i int = 0, @colors varchar(800);
DECLARE @results table(color varchar(40));
INSERT INTO @results SELECT color FROM...
DECLARE @temp table(Id INT, color varchar(40));
INSERT INTO @temp SELECT ROW_NUMBER() OVER (ORDER BY (SELECT 1)) AS Id, color FROM @results
WHILE (SELECT Count(*) FROM @temp WHERE color like '%<%') > 0
BEGIN
SELECT Top 1 @i = Id FROM @temp WHERE color like '%<%'
UPDATE @temp Set color = (case when color like '%<%'
then left(color, charindex('<', color) - 1)
else color
end) Where Id = @i
Delete @temp Where Id = @i
END
ich noch
color
------------------------------------------------------------------------------
Black, Blue<br/>PMS 285C, Green<br/>PMS 360, Red<br/>PMS 199
Könnte mir bekommen funktioniert jemand bitte helfen? Oder geben Sie einige Vorschläge.
Dank
bitte erklären, wie es funktioniert – Horaciux