sqlserver 自定义函数

sqlserver 自定义函数

 

http://wenku.baidu.com/view/7f9cf0bd960590c69ec376b4.html

eg.

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER FUNCTION [dbo].[Ph_GetMaoPiSL]
(
    @lb1 varchar(50),
    @maoPibianhao varchar(50)
)
RETURNS int
AS
BEGIN
    declare @linmaopisl int,@tuikusl int,@tuipiansl int    
    select @linmaopisl=isnull(sum(gw*sl),0) from insw where xmbh=@maoPibianhao and lb1=@lb1 and swdm='IM' AND kw1bh='FY00T'
    select @tuikusl=isnull(sum(gw*sl),0) from insw where xmbh=@maoPibianhao and lb1=@lb1 and swdm='TK' AND kw2bh='FY00T' AND kw1bh='TYP01'
    select @tuipiansl=isnull(sum(gw*sl),0) from insw where xmbh=@maoPibianhao and lb1=@lb1 and swdm='UT' AND kw2bh='FY00T' AND kw1bh='AP001'
    return @linmaopisl-@tuikusl-@tuipiansl
END
原文地址:https://www.cnblogs.com/xyzabc0004/p/2498498.html