Hi!
I have a task about analyzing data to generate some metadata about Products having values for specific measures or not. (Severalproducts of different types are stored in same table, but not all columns are relevant to allproducts, e.g a situation suitable for sparse columns)
That is to help users in avoiding selection of measures (100+) and getting disappointed when no values are present.
Currently there is no source for this type of meta data, so the solution is to read data from last month partition (until “today”)
Maybe you can suggest an smarter (faster) solution using DMV’s or something else?
It’s not difficult to generate some dynamic sql code like this:
SELECT ProductID
,CASE WHENmax(measure1)ISNOT NULLTHENconvert(bit, 1)elseconvert(bit, 0)end as measure1
,CASE WHENmax(measure2)ISNOT NULLTHENconvert(bit, 1)elseconvert(bit, 0)end as measure2
-- 100+ other signals….
from fct.MyFactWithManyMeasureswhere t >= convert(smalldatetime,'2014-07-01', 121)groupby ProductID
I also considered creation of statiscs:
CREATESTATISTICSmystatson fct.MyFactWithManyMeasures(measure1, … measureN ) where t>=convert(smalldatetime,'2014-07-01', 121)withfullscan;
And then looking at histogram, but only 32 columns are allowed. And creating many stats instead to cover all measures would mean reading data several times
Having these feature in mind:
ALTER TABLE … ALTER COLUMN … NOT NULL - SQL server rejects creation of NOT NULL columns, if you try to alter columns and data not allow it
SPARSE COLUMNS
I was thinking: maybe there exists some DMV/feature that can help me to tell if there are non-null data or not; I’m not even interested in the actual values, only their existence…
Best regards
Bjorn
B. D. Jensen