|
Question : aggregate function for varchar field
|
|
Is the a function or a way to create a function that will combine varchar results from a querey into an aggregate result? For example, if my result returns 4 rows of 1 field:
SELECT colors FROM myColors ---------------------- red blue green black
I want one row with one field returned:
SELECT CharSum(colors) FROM myColors ---------------------- red blue green black
Is there a function that can do this or a way to create a user defined "CharSum" function?
-Steve
|
|
Answer : aggregate function for varchar field
|
|
CREATE Function CharSum ()
Returns varchar(1000)
As Begin Declare @Colors varchar(1000) Set @Colors = '' Select @Colors = @Colors + Colors + ' ' From myColors
Return @Colors End
|
|
|