... until the collector arrives ...

This "blog" is really just a scratchpad of mine. There is not much of general interest here. Most of the content is scribbled down "live" as I discover things I want to remember. I rarely go back to correct mistakes in older entries. You have been warned :)

2008-11-28

Product Aggregation in SQL Server

Ever wanted to write something like this in SQL Server:

SELECT PRODUCT(MYCOLUMN) FROM MYTABLE

Well, wish no more:

DECLARE @P FLOAT
SET @P = 1
SELECT @P = @P * MYCOLUMN FROM MYTABLE
SELECT @P

... provided you can use the query in a context that permits T-SQL that is (e.g. not in a view or a subquery).  Note that you can perform arbitrary aggregations using this technique (say, summing while respecting null contagion, concatenating strings... the mind boggles).

Blog Archive