March 11, 2004 at 6:27 am
Is there a way to aggregate strings (concatenate), in a similar way as the Sum functions does with numbers.
March 11, 2004 at 6:44 am
Do you mean this
SELECT 'this string' + ' ' + 'has been concatenated'
or with variables
DECLARE @string1 varchar(30),@string2 varchar(30)
SET @string1 = 'this string'
SET @string2 = 'has been concatenated'
SELECT @string1 + ' ' + @string2
Far away is close at hand in the images of elsewhere.
Anon.
March 11, 2004 at 6:56 am
You can write a UDF specific to the table and column, e.g.:
USE Northwind
GO
CREATE FUNCTION dbo.f_ListCusts(@Country nvarchar(15)) RETURNS varchar(8000) BEGIN
DECLARE @List varchar(8000)
SELECT @List = ISNULL(@List + ',','') + CustomerID
FROM dbo.Orders
WHERE ShipCountry = @Country
GROUP BY CustomerID -- makes sense in this case but probably should not be used in yours...
RETURN @List END
SELECT ShipCountry, dbo.f_ListCusts(ShipCountry)
FROM dbo.Orders
GROUP BY ShipCountry
I suggest doing this at the presentation layer rather than the database back-end, though.
--Jonathan
March 11, 2004 at 7:07 am
No I mean, to use the function in a similar way as the Aggregate function: SUM or COUNT or .....
March 11, 2004 at 7:12 am
Jonathan, as usual, in on the ball here. His solution is the answer to your question (I overlooked the word sum doh ). If not can you post more details, including table ddl, input and expected results.
Far away is close at hand in the images of elsewhere.
Anon.
March 11, 2004 at 7:13 am
Give you give some sample data along with the desired result?
--
Frank Kalis
Microsoft SQL Server MVP
Webmaster: http://www.insidesql.org/blogs
My blog: http://www.insidesql.org/blogs/frankkalis/[/url]
March 11, 2004 at 7:14 am
Sorry Dave, haven't seen your response asking the same thing.
--
Frank Kalis
Microsoft SQL Server MVP
Webmaster: http://www.insidesql.org/blogs
My blog: http://www.insidesql.org/blogs/frankkalis/[/url]
March 11, 2004 at 7:18 am
Thats OK Frank,
Thought there was an echo
there was an echo
was an echo
an echo
echo
echo
FOTFL
Far away is close at hand in the images of elsewhere.
Anon.
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply