re: "In any case, you cannot join an array of one value or at least not perform any actions." - HLGEM Dec 30 '10 at 18:11
I can and definitely always join the comma-separated list.
In SQL 2000, they introduced UDF, and I often use the Split function to take a comma-separated list and turn it into a table.
With SQl 2005 and Newer, you can CROSS APPLY this function to join multiple rows (with a comma-separated list as one column) to denormalize it in the proper format.
I used this function to search property lists (for real estate), and it usually worked pretty well.
SELECT * FROM PropertyLists CROSS APPLY [OLReweAbf].[dbo].[udfSplit] (PropertyLists.propertyList,',') WHERE PropertyLists.Area = 104
SQL split function , herbee:
CREATE FUNCTION [dbo].[udfSplit](@text nvarchar(max), @delimiter char(1) = ' ') RETURNS @Strings TABLE ( position int IDENTITY PRIMARY KEY, value nvarchar(max) ) AS BEGIN DECLARE @index int SET @index = -1 WHILE (LEN(@text) > 0) BEGIN SET @index = CHARINDEX(@delimiter , @text) IF (@index = 0) AND (LEN(@text) > 0) BEGIN INSERT INTO @Strings VALUES (@text) BREAK END IF (@index > 1) BEGIN INSERT INTO @Strings VALUES (LEFT(@text, @index – 1)) SET @text = RIGHT(@text, (LEN(@text) – @index)) END ELSE SET @text = RIGHT(@text, (LEN(@text) – @index)) END RETURN END
source share