--标准正态分布函数
CREATE function [dbo].[normcdf] (   @p    decimal(28,18)       )                                                               
AS                                                                                                      
begin                                                                                                                                    
    declare @L decimal(28,18)                                                                                           
    declare @K decimal(28,18)                                                                                           
    declare @dCND decimal(28,18)                                                                                        
    declare @pi decimal(28,18)                                                                                          
                                                                                                               
    declare @a1 decimal(28,18)                                                                                          
    declare @a2 decimal(28,18)                                                                                          
    declare @a3 decimal(28,18)                                                                                           
    declare @a4 decimal(28,18)                                                                                           
    declare @a5 decimal(28,18)                                                                                           
                                                                                                                                                           
    select @L = 0.0                                                                                            
    select @K = 0.0                                                                                            
    select @dCND = 0.0                                                                                         
                                                                                                               
    select @a1 = 0.31938153                                                                                    
    select @a2 = -0.356563782                                                                                  
    select @a3 = 1.781477937                                                                                   
    select @a4 = -1.821255978                                                                                  
    select @a5 = 1.330274429                                                                                   
    select @pi = 3.1415926535897932384626433832795                                                             
    select @L = Abs(@p)                                                                                        
                                                                                                               
    if @L >= 30                                                                                                
    begin                                                                                                      
        if sign(@p) = 1 begin                                                                                  
            select @n_result = 1                                                                               
                                                                                               
        end else begin                                                                                         
            select @n_result = 0                                                                               
                                                                                               
           end                                                                                                 
    end                                                                                                        
    else                                                                                                       
    begin                                                                                                      
    -- perform calculation                                                                                     
        select @K = 1.0 / (1.0 + 0.2316419 * @L)                                                               
        select @dCND = 1.0 - 1.0 / Sqrt(2 * @pi) * Exp(-@L * @L / 2.0) *                                       
            (@a1 * @K + @a2 * @K * @K + @a3 * POWER(@K, 3.0) + @a4 * POWER(@K, 4.0) + @a5 * POWER (@K, 5.0))   
                                                                                                               
        if (@p < 0) begin                                                                                      
            select @n_result = 1.0 - @dCND                                                                     
                                                                                               
        end else begin                                                                                         
            select @n_result = @dCND                                                                           
                                                                                              
           end                                                                                                 
 end

return @n_result

end

--标准正态分布反函数
    CREATE  function [dbo].[norminv]  (@p decimal(28,18))
returns decimal(28,18)
as 
begin 
                                                                                            
declare @a1 decimal(28,18)                                                                                                                                                
declare @a2 decimal(28,18)                                                                                                                                                 
declare @a3 decimal(28,18)                                                                                                                                                 
declare @a4 decimal(28,18)                                                                                                                                                 
declare @a5 decimal(28,18)                                                                                                                                                 
declare @a6 decimal(28,18)                                                                                                                                                 
declare @b1 decimal(28,18)                                                                                                                                                 
declare @b2 decimal(28,18)                                                                                                                                                 
declare @b3 decimal(28,18)                                                                                                                                                
declare @b4 decimal(28,18)                                                                                                                                                
declare @b5 decimal(28,18)                                                                                                                                                 
declare @c1 decimal(28,18)                                                                                                                                                 
declare @c2 decimal(28,18)                                                                                                                                                 
declare @c3 decimal(28,18)                                                                                                                                                 
declare @c4 decimal(28,18)                                                                                                                                                 
declare @c5 decimal(28,18)                                                                                                                                                 
declare @c6 decimal(28,18)                                                                                                                                                 
declare @d1 decimal(28,18)                                                                                                                                                 
declare @d2 decimal(28,18)                                                                                                                                                 
declare @d3 decimal(28,18)                                                                                                                                                
declare @d4 decimal(28,18)                                                                                                                                                 
declare @plow decimal(28,18)                                                                                                                                               
declare @phigh decimal(28,18)                                                                                                                                              
declare @q decimal(28,18)                                                                                                                                                  
declare @r decimal(28,18)                                                                                                                                                  
declare @g_result decimal(28,18)                                                                                                                                                     
                                                                                                                                                            
                                                                                                                                                               
SET @a1 = -39.6968302866538                                                                                                                                     
SET @a2 = 220.946098424521                                                                                                                                      
SET @a3 = -275.928510446969                                                                                                                                     
SET @a4 = 138.357751867269                                                                                                                                      
SET @a5 = -30.6647980661472                                                                                                                                     
SET @a6 = 2.50662827745924                                                                                                                                      
SET @b1 = -54.4760987982241                                                                                                                                     
SET @b2 = 161.585836858041                                                                                                                                      
SET @b3 = -155.698979859887                                                                                                                                     
SET @b4 = 66.8013118877197                                                                                                                                      
SET @b5 = -13.2806815528857                                                                                                                                     
SET @c1 = -7.78489400243029E-03                                                                                                                                 
SET @c2 = -0.322396458041136                                                                                                                                    
SET @c3 = -2.40075827716184                                                                                                                                     
SET @c4 = -2.54973253934373                                                                                                                                     
SET @c5 = 4.37466414146497                                                                                                                                      
SET @c6 = 2.93816398269878                                                                                                                                      
SET @d1 = 7.78469570904146E-03                                                                                                                                  
SET @d2 = 0.32246712907004                                                                                                                                      
SET @d3 = 2.445134137143                                                                                                                                        
SET @d4 = 3.75440866190742                                                                                                                                      
SET @plow=0.02425                                                                                                                                               
SET @phigh=1-@plow                                                                                                                                              
                                                                                                                                                                  
if (@p<@plow)                                                                                                                                                     
begin                                                                                                                                                             
select @q = Sqrt(-2 * Log(@p))                                                                                                                                  
select @g_result=(((((@c1 * @q + @c2) * @q + @c3) * @q + @c4) * @q + @c5) * @q + @c6) / ((((@d1 * @q + @d2) * @q + @d3) * @q + @d4) * @q + 1)                   
                                                                                                                                                
end                                                                                                                                                               
else begin                                                                                                                                                        
if (@p<@phigh)                                                                                                                                                    
begin                                                                                                                                                             
select @q =@p - 0.5                                                                                                                                             
select @r = @q * @q                                                                                                                                             
select @g_result= (((((@a1 * @r + @a2) * @r + @a3) * @r + @a4) * @r + @a5) * @r + @a6) * @q / (((((@b1 * @r + @b2) * @r + @b3) * @r + @b4) * @r + @b5) * @r + 1)
                                                                                                                                               
end                                                                                                                                                               
else begin                                                                                                                                                        
select @q = Sqrt(-2 * Log(1 - @p))                                                                                                                              
select @g_result= -(((((@c1 * @q + @c2) * @q + @c3) * @q + @c4) * @q + @c5) * @q + @c6) / ((((@d1 * @q + @d2) * @q + @d3) * @q + @d4) * @q + 1)                 
                                                                                                                                                
end                                                                                                                                                             
end

return @g_result
end

正太分布函数和反函数 标量值函数 (借鉴)相关推荐

  1. sql server表值函数与标量值函数实际应用

    sql中的表值函数与标量值函数区别与用法 一 .表值函数又分为内联函数与多语句函数 (1)内联函数就是没有函数主体表是单个 SELECT. 下面是一个不带输入参数的表值函数 create functi ...

  2. 数据库sql创建标量值函数_使用JSON_VALUE()从JSON数据中提取标量值

    数据库sql创建标量值函数 In this article, we will explore JSON_VALUE() function in SQL Server to extract scalar ...

  3. 表值函数,标量值函数详解

    顾名思义:表值函数返回的是表,而标量值函数可以返回基类型 表值函数 用户定义表值函数返回 table 数据类型.对于内联表值函数,没有函数主体:表是单个 SELECT 语句的结果集. 以下示例创建了一 ...

  4. 浅谈表值函数和标量值函数

    表值函数有两种形式: 1.内联表值函数 Create FUNCTION Funtion_name ( --这里定义传入参数以及类型 ) RETURNS TABLE AS RETURN (--这里直接写 ...

  5. 表值函数和标量值函数

    Sql server 的表值函数是返回一个Table类型,table类型相当与一张存储在内存中的一张虚拟表. 实现表值函数很简单: 下面是一个不带输入参数的表值函数 create function t ...

  6. SQL Server 2008 创建标量值函数、存储过程

    在运用数据库的过程中,需要用到标量值函数以及存储过程. 仅以SQL Server 2008为例,对标量值函数以及存储过程的流程进行说明(标量值函数以及存储过程当中的代码不在这里讲述) 标量值函数 打开 ...

  7. TSQL:一列多行数据合并为一行的标量值函数写法

    一个业务场景,客户下了1个订单,出货的时候1个订单分了多次出货,出货单号存于表A,订单号数据存于表B,表A存有表B的ddid用于关联,统计报表要显示订单号对应的多次出货单,数据如下: 表A 表B dd ...

  8. sqlserver中的表值函数和标量值函数

    顾名思义:表值函数返回的是表,而标量值函数可以返回基类型 一.表值函数 用户定义表值函数返回 table 数据类型,表是单个 SELECT 语句的结果集. 以下示例: CREATE FUNCTION ...

  9. 根据输入时间日期返回时间、昨天、本周几、具体日期 类似于微信朋友圈时间 (msserver 标量值函数 )

    --根据输入时间日期返回时间.昨天.本周几.具体日期 类似于微信朋友圈时间 (msserver 标量值函数 ) --命名为中文,请勿喷 </pre><pre name="c ...

最新文章

  1. IE的box模型显示bug
  2. 使用 xcworkspace 管理 iOS 工程
  3. case例句java_case的一个用法--case 嵌套
  4. 万字好文 | B端产品设计指南
  5. 系统调研450篇文献,微软亚洲研究院推出超详尽语音合成综述
  6. Error response from daemon: manifest not found.
  7. 机器学习——决策树的三种学习方法
  8. android 开源组件合集-UI篇(2013-11-07更新)
  9. mac怎么用终端编写c语言视频,【新手提问】有知道用mac终端编c语言的网络编程的人吗?...
  10. sharepoint 2007功能增强解决方案,资料收集
  11. Python小白的数学建模课-04.整数规划
  12. P4888 三去矩阵
  13. Your branch is ahead of ‘origin/main‘ by 1 commit.
  14. TypeError: can only concatenate str (not “list“) to str 报错
  15. Java内存模型与共享变量可见性
  16. Python(九)- 音频文字转换
  17. tortoise-orm 分页码(python)
  18. 关于以太网没有有效的ip配置问题解决方法
  19. webpack基础篇(三):管理资源(image、css、fonts、csv、json5)
  20. MATLAB 用高斯消元法求解线性方程组

热门文章

  1. wireshark无法测同一个局域网固定ip的数据_局域网安全攻防
  2. 【AE扩展插件问题解决记录】
  3. C语言随机数:rand()和srand(time(NULL))的使用
  4. java web 有什么区别吗_web和java一样吗?有什么区别?
  5. 北航计算机学院往年夏令营+考研面试题目汇总
  6. 陈皓:什么是工程师文化?
  7. 金融数据分析 实验四 金融风险价值计算
  8. anz的swift code_澳洲Commonwealth bank是不是只有一个SWIFT CODE?
  9. 记录一次Visual Studio运行webservice调用中控打卡机出现的问题
  10. Android 标题栏及导航栏设计与实现