-- Note: The SQL aggragate function STDDEVP would normally be used here --
DECLARE
@stddev float;
DECLARE @tvalues TABLE
(
RowNum int IDENTITY PRIMARY KEY,
RowValue float
)
INSERT INTO @tvalues SELECT 3;
INSERT INTO @tvalues SELECT 7;
INSERT INTO @tvalues SELECT 7;
INSERT INTO @tvalues SELECT 19;
--Step 1: Generate basic stats
WITH stats
AS
(
SELECT AVG(RowValue) as av, Count(*) as cnt
FROM @tvalues
)
--Step 2: Sum the squares of the difference
SELECT POWER(SUM(POWER((RowValue - av),2))/cnt,0.5)
FROM @tvalues CROSS JOIN stats
GROUP BY cnt,av