一、单语句表值函数

ALTER       function [dbo].[uf_get_jxc_da_sum](@dt char(8),@dt2 char(8))
RETURNS table
as
return(
select aa.outlet_id,aa.store_id as storespace_id,aa.supp_id as supplier_id,aa.aid, aa.q as curr_q, aa.ea as curr_ea , aa.ra as curr_ra,aa.dj_ea as curr_dj_ea,
quota_q
,quota_ea
,quota_ra
,quota_diff_ea
,quota_diff_ra
,entry_q
,entry_ea
,entry_ra
,transferin_q
,transferin_ea
,transferin_ra
,retquota_q
,retquota_ea
,retquota_ra
,retpurchase_q
,retpurchase_ea
,retpurchase_ra
,transferout_q
,transferout_ea
,transferout_ra
,pftloss_in_q
,pftloss_in_ea
,pftloss_in_ra
,pftloss_out_q
,pftloss_out_ea
,pftloss_out_ra
,inventory_in_q
,inventory_in_ea
,inventory_in_ra
,inventory_out_q
,inventory_out_ea
,inventory_out_ra
,movestock_q
,movestock_ea
,movestock_ra
,sale_q
,sale_ea
,sale_ra
,favour_ra
,fifo_adjust_in_q
,fifo_adjust_in_ea
,fifo_adjust_out_q
,fifo_adjust_out_ea
,adjust_in_ea
,adjust_in_ra
,adjust_out_ea
,adjust_out_ra
,retpurchase_dj_ea,
case left(aa.outlet_id,1) when 'D' then (isnull(q,0) - isnull(entry_q,0) + isnull(quota_q,0) - isnull(fifo_adjust_in_q,0) - isnull(pftloss_in_q,0) - isnull(inventory_in_q,0) + isnull(sale_q,0) - isnull(retquota_q,0) + isnull(retpurchase_q,0) + isnull(pftloss_out_q,0) + isnull(inventory_out_q,0) + isnull(fifo_adjust_out_q,0))
else (isnull(q,0) - isnull(entry_q,0) - isnull(quota_q,0) - isnull(fifo_adjust_in_q,0) - isnull(pftloss_in_q,0) - isnull(inventory_in_q,0) - isnull(transferin_q,0) + isnull(sale_q,0) + isnull(retquota_q,0) + isnull(retpurchase_q,0) + isnull(pftloss_out_q,0) + isnull(inventory_out_q,0) + isnull(fifo_adjust_out_q,0) + isnull(transferout_q,0))
end as last_q,
case left(aa.outlet_id,1) when 'D' then (isnull(ea,0) - isnull(entry_ea,0) + isnull(quota_ea,0) - isnull(fifo_adjust_in_ea,0) - isnull(pftloss_in_ea,0) - isnull(inventory_in_ea,0) - isnull(adjust_in_ea,0) + isnull(sale_ea,0) - isnull(retquota_ea,0) + isnull(retpurchase_ea,0) + isnull(pftloss_out_ea,0) + isnull(inventory_out_ea,0) + isnull(fifo_adjust_out_ea,0) + isnull(adjust_out_ea,0))
else (isnull(ea,0) - isnull(entry_ea,0) - isnull(quota_ea,0) - isnull(fifo_adjust_in_ea,0) - isnull(pftloss_in_ea,0) - isnull(inventory_in_ea,0) - isnull(adjust_in_ea,0) - isnull(transferin_ea,0) + isnull(sale_ea,0) + isnull(retquota_ea,0) + isnull(retpurchase_ea,0) + isnull(pftloss_out_ea,0) + isnull(inventory_out_ea,0) + isnull(fifo_adjust_out_ea,0) + isnull(adjust_out_ea,0) + isnull(transferout_ea,0))
end as last_ea,
case left(aa.outlet_id,1) when 'D' then (isnull(ra,0) - isnull(entry_ra,0) + isnull(quota_ra,0) - isnull(pftloss_in_ra,0) - isnull(inventory_in_ra,0) - isnull(adjust_in_ra,0) + isnull(sale_ra,0) + isnull(favour_ra,0) - isnull(retquota_ra,0) + isnull(retpurchase_ra,0) + isnull(pftloss_out_ra,0) + isnull(inventory_out_ra,0) + isnull(adjust_out_ra,0))
else (isnull(ra,0) - isnull(entry_ra,0) - isnull(quota_ra,0) - isnull(pftloss_in_ra,0) - isnull(inventory_in_ra,0) - isnull(adjust_in_ra,0) - isnull(transferin_ra,0) + isnull(sale_ra,0) + isnull(favour_ra,0) + isnull(retquota_ra,0) + isnull(retpurchase_ra,0) + isnull(pftloss_out_ra,0) + isnull(inventory_out_ra,0) + isnull(adjust_out_ra,0) + isnull(transferout_ra,0))
end as last_ra,
-- case left(aa.outlet_id,1) when 'D' then (isnull(dj_ea,0) - isnull(entry_ea,0) + isnull(quota_ea,0) - isnull(fifo_adjust_in_ea,0) - isnull(pftloss_in_ea,0) - isnull(inventory_in_ea,0) - isnull(adjust_in_ea,0) + isnull(sale_ea,0) - isnull(retquota_ea,0) + isnull(retpurchase_dj_ea,0) + isnull(pftloss_out_ea,0) + isnull(inventory_out_ea,0) + isnull(fifo_adjust_out_ea,0) + isnull(adjust_out_ea,0))
-- else (isnull(dj_ea,0) - isnull(entry_ea,0) - isnull(quota_ea,0) - isnull(fifo_adjust_in_ea,0) - isnull(pftloss_in_ea,0) - isnull(inventory_in_ea,0) - isnull(adjust_in_ea,0) - isnull(transferin_ea,0) + isnull(sale_ea,0) + isnull(retquota_ea,0) + isnull(retpurchase_ea,0) + isnull(pftloss_out_ea,0) + isnull(inventory_out_ea,0) + isnull(fifo_adjust_out_ea,0) + isnull(adjust_out_ea,0) + isnull(transferout_ea,0))
-- end as last_dj_ea
(isnull(dj_ea,0) - isnull(entry_ea,0) - isnull(fifo_adjust_in_ea,0) - isnull(pftloss_in_ea,0) - isnull(inventory_in_ea,0) - isnull(adjust_in_ea,0) + isnull(sale_ea,0) + isnull(retpurchase_dj_ea,0) + isnull(pftloss_out_ea,0) + isnull(inventory_out_ea,0) + isnull(fifo_adjust_out_ea,0) + isnull(adjust_out_ea,0)) as last_dj_ea
from
dbo.uf_get_stock_da_curr(@dt2) aa
left join
dbo.uf_get_jxc_sum(@dt,@dt2) bb
on
aa.outlet_id = bb.outlet_id
and aa.store_id = bb.storespace_id
and aa.supp_id = bb.supplier_id
and aa.aid = bb.aid
where left(aa.outlet_id,1)<>'8'
)

  

二、多语句表值函数

alter function [dbo].[f_getFjxx](@fjh varchar(50),@dt varchar(10))
returns @fjxx table (FJXXMX_FJH varchar(10) NULL,FJXXMX_HKGSDM varchar(10) NULL,FJXXMX_3ZM varchar(10) NULL,FJXXMX_ZDQFQZ float NULL,FJXXMX_ZDZW float NULL,FJXXMX_KGZW float NULL,FJXXMX_ZDYZ float NULL,FJXXMX_KGYZ float NULL,FJXXMX_XGRQ datetime NULL)
as
begin
declare @id int,
@max_xgrq varchar(10)
select @max_xgrq= max(CONVERT(varchar(10),fjxxmx_xgrq,120)) from ARP_FJXXMX where FJXXMX_FJH=@fjh and @dt>=CONVERT(varchar(10),fjxxmx_xgrq,120)
select @id= fjxxmx_id from ARP_FJXXMX where FJXXMX_FJH=@fjh and CONVERT(varchar(10),fjxxmx_xgrq,120)=@max_xgrq insert into @fjxx(FJXXMX_FJH,FJXXMX_HKGSDM,FJXXMX_3ZM,FJXXMX_ZDQFQZ,FJXXMX_ZDZW,FJXXMX_KGZW,FJXXMX_ZDYZ,FJXXMX_KGYZ,FJXXMX_XGRQ)
select FJXXMX_FJH,FJXXMX_HKGSDM,FJXXMX_3ZM,FJXXMX_ZDQFQZ,FJXXMX_ZDZW,FJXXMX_KGZW,FJXXMX_ZDYZ,FJXXMX_KGYZ,FJXXMX_XGRQ
from ARP_FJXXMX where FJXXMX_ID=@id
return
end

  

sqlserver 表值函数的更多相关文章

  1. sqlserver 表值函数与标量值函数

    除了在我们常用的程序开发中要用到函数外,在sql语句中也常用到函数,不论哪种,思想都没有变,都是为了封装,可复用. 创建的方法和整体结构都大体相同,都少不了函数名,函数的形参,返回值等这些. 一.表值 ...

  2. Sqlserver表值函数来获取逗号分隔的ID

    其功能为: 将字符串如'1,2,3,4,5,6' 拼接成SQL里面的id 1:使用: select * from Student where id IN( SELECT * FROM dbo.F_SP ...

  3. SQL Server中使用表值函数

    函数有很多限制,不能使用动态语句,不能使用临时表等等...细看一下,直接写语句就行了,不用动态语句 insert into @re select id,parid,@I from videoclass ...

  4. SqlServer使用表值函数汇总

    先谈谈需求,我们先创建一张表,脚本如下: create table Cost ( Id ,) primary key,--编号 CostTime date,--时间 Num int--销售额 ); ' ...

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

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

  6. SQLServer之修改表值函数

    修改表值函数注意事项 更改先前通过执行 CREATE FUNCTION 语句创建的现有 Transact-SQL 或 CLR 函数,但不更改权限,也不影响任何相关的函数.存储过程或触发器. 不能用 A ...

  7. SQLServer之创建表值函数

    表值函数创建注意事项 用户定义表值函数返回 table 数据类型. 对于内联表值函数,没有函数主体,表是单个 SELECT 语句的结果集. 表值函数主要用于数据计算出来返回结果集. 使用SSMS数据库 ...

  8. sqlserver自定义函数(标量值函数,表值函数)

    用户自定义的函数有两类:表值函数.标量值函数. 表值函数:返回值是数据表的函数 调用方式 select  b.*  from tableA a accross apply Fun_BiaoZhiFun ...

  9. 用程序集编写clr表值函数:把正则表达式引入数据库中

    正则表达式非常好,但在数据库中就是没有,但可以通过程序集方式扩展 先编写一个dll,标量函数很好写,表值函数麻烦一点 下面是C#代码 using System; using System.Data; ...

随机推荐

  1. 在vue-cli中使用路由

    1.首先npm中是否有vue-router 一般在vue-cli的时候就已经下载好了依赖包了 2.使用vue的话正常的需要涉及这几个文件 demo/src/router/index.js import ...

  2. 轻松搞定Struts 2:三步走上手小入门

    零.Struts 2是啥? SSH.SSM.SSI如雷贯耳,Struts 2 —— 是的,就这样了... 一.Hello Struts2 1.核心包 2.struts.xml核心控制器配置 <f ...

  3. Q9400为何难以100%全速运行

    采用基于正域的约简. 数据:Ticdata2000 记录数:5822 条件属性:85 结果: 1. Core i7 3632QM 4四核八线程 2.2G 动态加速3.2G 0.516s 2. Core ...

  4. 【BZOJ1057】[ZJOI2007] 棋盘制作(单调栈的运用)

    点此看题面 大致题意: 给你一个\(N*M\)的\(01\)矩阵,要求你分别求出最大的\(01\)相间的正方形和矩形(矩形也可以是正方形),并输出其面积. 题解 这题第一眼看去没什么思路,仔细想想,能 ...

  5. 使用canvas给图片添加水印

    css部分 .clip { position: absolute; clip: rect(0 0 0 0); } html部分 <input type="file" id=& ...

  6. MicroService 微服务提供者搭建

    本机IP为  192.168.1.102 1.  新建Maven项目   microservice 2.   pom.xml <project xmlns="http://maven. ...

  7. GPU并行编程:内核及函数的实现

    原文链接 回想一下我们之前在设备上使用“kernelFunction<<<1,1>>>(..)”执行一个函数的代码,我在那里还曾说过后面会细说,本文就详细介绍一下参 ...

  8. java设计模式——建造者模式

    一. 定义与类型 定义:将一个复杂对象的构建与它的表示分离,使用同样的构建过程可以创建不同的表示 用户只需制定需要建造的类型就可以得到它们,建造过程以及细节不需要知道 类型:创建型 建造者模式与工厂模 ...

  9. 网络编程——TCP协议和通信

    第1章 TCP通信 TCP通信同UDP通信一样,都能实现两台计算机之间的通信,通信的两端都需要创建socket对象. 区别在于,UDP中只有发送端和接收端,不区分客户端与服务器端,计算机之间可以任意地 ...

  10. STL MAP使用注意事项

    Hat’s Words A hat’s word is a word in the dictionary that is the concatenation of exactly two other ...