I need to construct a blob that captures series of (datetime, float)
tuples. They are sampled sensor values that are initially collected in the SQL table with the columns of the types. After a while, they should be converted to blob and stored in another kind of records. When needed, the blob should be expanded back to the (say temporary) table.
Because of more complex processing of the samples, the raw SQL language is not suitable for implementation of the functionality. On the other hand, I would like to implement the CLR assembly the way to be flexible when used.
So far, I have implemented the aggregate function that can be called like this:
SELECT
MIN(UTC) AS min_utc,
MAX(UTC) AS max_utc,
Aggregates.TimeValuesBlob(UTC, sensor_value) AS result
FROM SensorData.dbo.sensor_values
WHERE UTC BETWEEN '2012-09-14 08:00' AND '2012-09-14 12:25'
However, the aggregate function can return 8000 bytes at maximum. I need to construct bigger blobs. How to do that? What features/mechanisms of the MS-SQL Server (version 2012 and possibly also 2008 R2) should be used?
Is it necessary to to write a CLR stored procedure and pass the SQL command as the argument? Is it possible to use the same SQL command as above, parse it internally, do the aggreagation on my own? Or should I rethink the approach?
Take a look at this: SQL Server Compressed Rowset Sample which you might want to use, or at least for how to do that sort of thing.