/* Calculate Factorial *//* SQL Server => 2012 */DECLARE @TOP BIGINT = 22;;WITH NUMBERS AS(SELECT CAST(ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) AS FLOAT(53)) AS NFROM (VALUES (1), (1), (1), (1), (1), (1), (1), (1)) AS A(N),(VALUES (1), (1), (1), (1), (1), (1), (1), (1)) AS B(N)ORDER BY 1 OFFSET 0 ROWS FETCH FIRST (@TOP) ROWS ONLY),N_EXP AS(SELECT ROW_NUMBER() OVER (PARTITION BY N2.N ORDER BY (SELECT NULL)) AS N_RID ,N2.N AS N ,EXP(SUM(LOG(N1.N)) OVER (PARTITION BY N2.N)) AS N_EXP ,CAST(EXP(CAST((SUM(CAST(LOG(N1.N) AS DECIMAL(38,16))) OVER (PARTITION BY N2.N)) AS DECIMAL(38,16))) AS DECIMAL(38,16)) AS N_DCEXPFROM NUMBERS N1CROSS JOIN NUMBERS N2WHERE N1.N <= N2.N)SELECT NX.N AS N ,NX.N_EXP AS NX_EXP ,CAST(NX.N_EXP AS DECIMAL(38,16)) AS NX_EXPD ,NX.N_DCEXP AS NX_DDEXP ,STR(NX.N_EXP,38,16) AS NX_STRFROM N_EXP NXWHERE NX.N_RID = 1;

CREATE TABLE #t2 (a float)GOINSERT #t2SELECT CAST(somenumber AS float)FROM #MyHeadDECLARE @BitBucket VARCHAR(10) SELECT @BitBucket = STR(a,10) FROM #t2