给个存储过程的例子看看,谢了
解决方案 »
- 关于DBGrid显示问题
- delphi 怎么在DBF表里面添加数据
- 500分求解:Delphi中如何在主窗体中定义及使用“创建窗体的自定义函数”等序列问题,望过来人答疑解惑!
- 销售社保局用养老保险软件或者源代码
- 散分--给可怜的人
- Application.Initialize有什么用啊,见者有分
- 各位大哥,高手们,我再也没有什么问题可以问了,只有送分了!-------我最心爱的东西居然被人无情的夺走了!(来者皆高分相送!)
- 山东济南诚聘软件开发人员!!
- 寻找解决delphi5多媒体控件无法播放vcd文件的bug?
- Windows2000 professional共享目录密码问题
- ADO为什么要这么变态?还是我太菜?求教
- delphi中ntohl函数如何调用?
drop proc usp_zyb_brjs_1
go
create proc usp_zyb_brjs_1
@syxh ut_syxh,
@jsfs smallint = 2,
@jsqk smallint = 0,
@czyh ut_czyh = null,
@jsje_bsxj numeric(12,2) = 0,
@skfs_xj ut_dm2 = '1',
@jsje_bszp numeric(12,2) = 0,
@skfs_zp ut_dm2 = '2',
@zhbz ut_zhbz = null,
@zddm ut_zddm = null,
@zxlsh ut_lsh = null,
@jslsh ut_lsh = null,
@qfdnzhzfje numeric(12,2) = null,
@qflnzhzfje numeric(12,2) = null,
@qfxjzfje numeric(12,2) = null,
@tclnzhzfje numeric(12,2) = null,
@tcxjzfje numeric(12,2) = null,
@tczfje numeric(12,2) = null,
@fjlnzhzfje numeric(12,2) = null,
@fjxjzfje numeric(12,2) = null,
@dffjzfje numeric(12,2) = null,
@dnzhye numeric(12,2) = null,
@lnzhye numeric(12,2) = null,
@dfpbz smallint = 0,
@khyh varchar(50)=null,
@zph varchar(50)=null
,@ylcardno ut_cardno=''
,@ylksqxh ut_lsh=''
,@ylkzxlsh ut_lsh=''
,@rqbz ut_bz=0
,@jsrq ut_rq16=null
,@mxxh varchar(8000) =null --明细费用序号列表,以,号分割
,@jsjein_txj numeric(12,2) = 0.00
,@jsjein_tzp numeric(12,2) = 0.00
,@zfzje numeric(12,2)=null,
@yydftcje numeric(12,2)=null,
@bnyzftcj numeric(12,2)=null,
@bnynrtcfw numeric(12,2)=null,
@tcjjzje numeric(12,2)=null,
@dwfdje numeric(12,2)=null,
@sxzfje numeric(12,2)=null,
@zhdejzj numeric(12,2)=null,
@zhtcj numeric(12,2)=null,
@zfzhdejzj numeric(12,2)=null,
@zfzhtcj numeric(12,2)=null,
@bczfgrzh numeric(12,2)=null,
@jbfy numeric(12,2)=null,
@fjbfy numeric(12,2)=null,
@mtzyqf numeric(12,2)=null,
@tcjjzf numeric(12,2)=null,
@dbjjzf numeric(12,2)=null,
@zhyje numeric(12,2)=null, @nbzje numeric(12,2)=null, --总金额
@nbkbje numeric(12,2)=null,--本次可报金额
@nbbcbcje numeric(12,2)=null,--本次补偿金额
@nbbnbcje numeric(12,2)=null, --本年补偿金额
@nbfplsh varchar(32) --农保发票流水号--add by ctg at 20060923
as
/**********
[参数说明]
@syxh ut_syxh, 首页序号
@jsfs smallint = 2, 结算方式1=在院,2=出院
@jsqk smallint = 0, 结算情况0=结算金额,1=结算1,2=执行结算,3=欠款出院
@czyh ut_czyh = null 操作员号
@jsje_bsxj numeric(12,2) = 0, 在院结算或欠款结算时追加金额(现金类)
@skfs_xj ut_dm2 = '0' 收款方式(现金类)
@jsje_bszp numeric(12,2) = 0, 在院结算或欠款结算时追加金额(支票类)
@skfs_zp ut_dm2 = '0' 收款方式(支票类)
@zhbz ut_zhbz = null, 账户标志
@zddm ut_zddm = null, 诊断代码
@zxlsh ut_lsh = null, 中心流水号
@jslsh ut_lsh = null, 计算流水号
@qfdnzhzfje numeric(12,2) = null, 起付段当年账户支付
@qflnzhzfje numeric(12,2) = null, 起付段历年帐户支付
@qfxjzfje numeric(12,2) = null, 起付段现金支付
@tclnzhzfje numeric(12,2) = null, 统筹段历年帐户支付
@tcxjzfje numeric(12,2) = null, 统筹段现金支付
@tczfje numeric(12,2) = null, 统筹段统筹支付
@fjlnzhzfje numeric(12,2) = null, 附加段历年帐户支付
@fjxjzfje numeric(12,2) = null, 附加段历金支付
@dffjzfje numeric(12,2) = null 附加段地方附加支付
@dnzhye numeric(12,2) = null, 当年账户余额
@lnzhye numeric(12,2) = null, 历年账户余额
@dfpbz smallint = 0 多发票打印标志0=单发票,1=多发票
@khyh varchar(50)=null, 开户银行
@zph varchar(50)=null 支票号
--mit ,, 2oo3-o5-o8 ,, 银联卡参数
,@ylcardno ut_cardno='' --银联卡卡号
,@ylksqxh ut_lsh='' --银联卡新申请序号
,@ylkzxlsh ut_lsh='' --银联卡新中心流水号
--tony 2003.09.16 在院结算到日期
,@rqbz ut_bz=0 0在院结算到当前为止,1在院结算到指定日期
,@jsrq ut_rq16=null 在院结算日期
,@mxxh varchar(500) =null --明细费用序号列表,以,号分割
@zfzje numeric(12,2)=null, 自负总金额
@yydftcje numeric(12,2)=null, 医院垫付金额
@bnyzftcj numeric(12,2)=null, 本年应支付统筹金
@bnynrtcfw numeric(12,2)=null, 本年已纳入统筹范围
@tcjjzje numeric(12,2)=null, 统筹及救助金额
@dwfdje numeric(12,2)=null, 单位负担金额
@sxzfje numeric(12,2)=null, 首先自负金额
@zhdejzj numeric(12,2)=null, 暂缓大额救助金
@zhtcj numeric(12,2)=null, 暂缓统筹金
@zfzhdejzj numeric(12,2)=null, 支付暂缓大额救助金
@zfzhtcj numeric(12,2)=null, 支付暂缓统筹金
@bczfgrzh numeric(12,2)=null, 本次支付个人帐户
@jbfy numeric(12,2)=null, 基本费用
@fjbfy numeric(12,2)=null, 非基本费用
@mtzyqf numeric(12,2)=null, 门特或住院起付
@tcjjzf numeric(12,2)=null, 统筹基金支付
@dbjjzf numeric(12,2)=null, 大病基金支付
@zhyje numeric(12,2)=null 帐户原金额
[返回值]
[结果集、排序]
[调用的sp]
**********/
declare @ybdm ut_ybdm, --医保代码
@now ut_rq16, --当前时间
@zfbz smallint, --比例标志
@zje ut_money, --总金额
@zje1 ut_money, --已结算总金额
@zfyje ut_money, --自费金额
@zfyje1 ut_money, --已结算自费金额
@yhje ut_money, --优惠金额
@yhje1 ut_money, --已结算优惠金额
@ybje ut_money, --可用于医保计算的金额
@ybje1 ut_money, --已结算可用于医保计算的金额
@pzlx ut_dm2, --凭证类型
@sfje ut_money, --实收金额
@sfje1 ut_money, --已结算实收金额
@sfje_all ut_money, --实收金额(包含自费金额)
@errmsg varchar(50),
@srbz char(1), --舍入标志
@srje ut_money, --舍入金额
@sfje2 ut_money, --舍入后的实收金额
@xhtemp ut_xh12,
@fph int, --发票号
@fpjxh ut_xh12, --发票卷序号
@deje ut_money, --定额金额
@deje1 ut_money, --剩余定额金额
@ryrq ut_rq16, --入院日期
@cqrq ut_rq16, --出区日期
@maxjsrq ut_rq16, --最大在院结算日期
@jgbz smallint, --急观标志0=住院,1=在观,2=出观
@cardtype ut_dm2, --卡类型
@brlx char(1), --病人类型
@ybstr varchar(350), --医保字符串(加长)
@cardno ut_cardno, --卡号
@tsrybz char(1), --特殊人员标志
@strybje char(10), --医保费用总额
@zyts numeric(10,1), --住院天数
@zyts1 numeric(10,1), --已结算住院天数
@jsxh ut_xh12, --结算序号
@yjlj money, --押金累计
@xjlj money, --现金累计
@zplj money, --支票累计
@print smallint, --预交金收据打印标志0=不打,1=打印
@tcljje numeric(12,2), --统筹累计金额
@ybjsfs ut_bz, --医保计算方式
@qqqklj ut_money --前期欠款累计
--tony 2003.09.16 医保四期
,@flzfje ut_money --分类自负金额
,@flzfje1 ut_money --已结算分类自负金额
,@strybjsje char(10) --医保结算范围金额
,@strzyf char(10) --住院费
,@strzlf char(10) --诊疗费
,@strzlf1 char(10) --治疗费
,@strhlf char(10) --护理费
,@strssclf char(10) --手术材料费
,@strjcf char(10) --检查费
,@strhyf char(10) --化验费
,@strspf char(10) --摄片费
,@strtsf char(10) --透视费
,@strsxf char(10) --输血费
,@strsyf char(10) --输氧费
,@strxyf char(10) --西药费
,@strzcyf char(10) --中成药费
,@strcyf char(10) --中草药费
,@strqtf char(10) --其他费
,@strzfje char(10) --非医保计算范围金额
,@zje2 ut_money --剩余总金额
,@zfyje2 ut_money --剩余自费金额
,@yhje2 ut_money --剩余优惠金额
,@flzfje2 ut_money --剩余分类自负金额
,@yjejz smallint --预交金结转标志 0=不结转,1=结转
--mit , 广州增加, 单项目结算
,@strsql varchar(8000) --执行strsql,mit, 2004-07-22
,@zyjslb ut_bz --在院结算类别,mit, 2004-07-22
,@isztjz ut_bz --预交金是否中途结转,jjw, 2005-02-19
,@zyrq ut_rq16
,@ybpz ut_zhbz
select @now=convert(char(8),getdate(),112)+convert(char(8),getdate(),8),
@zje=0, @zfyje=0, @yhje=0, @ybje=0,
@zje1=0, @zfyje1=0, @yhje1=0, @ybje1=0,
@sfje=0, @sfje1=0, @sfje_all=0, @srje=0, @sfje2=0,
@deje=0, @deje1=0, @zyts=0, @zyts1=0,
@yjlj=0, @xjlj=0, @zplj=0, @print=0, @tcljje=0,@qqqklj=0
--tony 2003.09.16 医保四期
,@flzfje=0,@flzfje1=0,@zje2=0,@zfyje2=0,@yhje2=0,@flzfje2=0
,@zyjslb=0 --mit , 2004-07-22 ,如果是选择项目结算,则归入选择日期的在院结算
if isnull(@mxxh,'')<>''
begin
select @rqbz=1,@jsrq=@now,@zyjslb=1
end
--yxp add 2004-02-12 如果病人费用明细中存在归类科目(大类)不正确的药品则提示
if exists(select 1 from ZY_BRFYMXK (nolock)
where syxh=@syxh and ltrim(rtrim(isnull(dxmdm,''))) not in (select id from YY_SFDXMK (nolock)) )
begin
select "F","病人费用明细中存在归类科目(大类)不正确的药品,请检查药品字典设置!"
return
end
if exists (select * from YY_CONFIG (nolock) where id='5036' and config='是')
update ZY_BRSYK set cqrq= @now where syxh=@syxh and jgbz=1
if @jsqk in (0,2,3)
begin
select * into #brsyk from ZY_BRSYK where syxh=@syxh and brzt not in (0, 3, 8, 9)
if @@error<>0 or @@rowcount=0
begin
select "F","病人首页信息不存在!"
return
end
select @ybdm=ybdm, @deje=deje, @ryrq=ryrq, @cqrq=cqrq, @jgbz=jgbz, @cardtype=cardtype, @brlx=brlx,
@zhbz=(case when @jsqk=0 and zhbz<>'' then zhbz else @zhbz end), @cardno=cardno, @jgbz=jgbz, @maxjsrq=ryrq,
@tcljje=isnull(tcljje,0),@ybpz=zhbz
from #brsyk
--tony 2003.09.16 在院结算到日期
if @jsfs=1 and @rqbz=0
select @cqrq=@now
else if @jsfs=1 and @rqbz=1
select @cqrq=@jsrq
select @pzlx=pzlx, @tsrybz=tsrydm, @ybjsfs=jsfs from YY_YBFLK where ybdm=@ybdm
if @@rowcount=0 or @@error<>0
begin
select "F","患者费用类别不正确!"
return
end
if @jsfs=2 and @jsqk in (2,3) and @pzlx <> '21' and exists(select 1 from BQ_FYQQK where syxh=@syxh and jlzt=0 and qqlx<>2 and zbbz <> 1)
begin
select "F","病人尚有药品未发,请先发药再出院!"
return
end
if @jsfs=2 and @jsqk in (2,3) and @pzlx <> '21' and exists(select 1 from BQ_SYCFMXK where syxh=@syxh and jlzt=0 and zbbz <> 1)
begin
select "F","病人尚有输液药品未发,请先发药再出院!"
return
end
if @jsfs=2 and @jsqk in (2,3) and @pzlx <> '21' and exists(select 1 from BQ_YJQQK where syxh=@syxh and jlzt=0)
begin
select "F","病人医技项目未确认,请先确认再出院!"
return
end
if @pzlx='21'
select @tsrybz=isnull(substring(@zhbz,4,1),'0')
--add by ctg
if exists(select 1 from ZY_BRJSK where syxh=@syxh and ybjszt=0) and @pzlx='21' and @jsqk in (2,3)
begin
select "F","请先进行预结算!"
return
end
select @zje1=isnull(sum(zje),0), @zfyje1=isnull(sum(zfyje),0), @yhje1=isnull(sum(yhje),0),
@sfje1=isnull(sum(zfje-srje),0), @zyts1=isnull(sum(zyts),0), @maxjsrq=isnull(max(jzrq),@maxjsrq),
@flzfje1=isnull(sum(flzfje),0)
from ZY_BRJSK where syxh=@syxh and jszt=1 and jlzt=0
end
select * into #brjsk from ZY_BRJSK where syxh=@syxh and jszt=0 and jlzt=0
if @@rowcount=0 or @@error<>0
begin
select "F","患者结算库中没有该患者记录!"
return
end
select @zje=zje, @zfyje=zfyje, @yhje=yhje, @flzfje=flzfje, @jsxh=xh from #brjsk
--tony 2003.09.16 在院结算到日期
if @jsqk <> 1
begin
select dxmdm, dxmmc, xmje, zfje, yhje, flzfje, yeje into #jsmxk
from ZY_BRJSMXK where jsxh=@jsxh
if @@error<>0
begin
select "F","计算病人结算明细出错!"
return
end
end
--modify by Wang Yi, 2003.09.29, 先判断结算情况,然后再根据结算方式生成临时表
if @jsqk in (0,2,3)
begin
--add by Wang Yi, 2003.09.29, 先创建#fymxk的结构
select dxmdm, zje xmje, zfje, yhje, flzfje, zje yeje into #fymxk
from ZY_BRFYMXK where 1=2
if @@error<>0
begin
select "F","创建临时表结构失败!"
return
end
--待结算金额 2004.03.08 zwj
select dxmdm, zje xmje, zfje, yhje, flzfje, zje yeje into #fymxk1
from ZY_BRFYMXK where 1=2
--tony 2003.09.16 在院结算到日期
if @jsfs=1 and isnull(@mxxh,'')<>''
begin
select @strsql='insert into #fymxk '
+ ' select dxmdm, sum(zje) xmje, sum(zfje) zfje, '
+ ' sum(yhje) yhje, sum(flzfje) flzfje, sum(case when yexh>0 then zje else 0 end) yeje '
+ ' from ZY_BRFYMXK '
+ ' where syxh=' + convert(varchar(16),@syxh)
+ ' and xh in ' + @mxxh
+ ' and jsxh not in(select xh from ZY_BRJSK where syxh=' + convert(varchar(16),@syxh) + ' and ybjszt=2 and jlzt=0 and jszt=1 and zyjslb=1) '
+ ' group by dxmdm '
exec(@strsql)
end
else if @jsfs=1 and @rqbz=1
begin
insert into #fymxk
select dxmdm, sum(zje) xmje, sum(zfje) zfje,
sum(yhje) yhje, sum(flzfje) flzfje, sum(case when yexh>0 then zje else 0 end) yeje
from ZY_BRFYMXK
where syxh=@syxh and zxrq<=@jsrq
and jsxh not in(select xh from ZY_BRJSK where syxh=@syxh and ybjszt=2 and jlzt=0 and jszt=1 and zyjslb=1)
group by dxmdm
end
else
begin
--正常结算直接取结算库信息 zwj 2004.03.08
insert into #fymxk1
select dxmdm, xmje, zfje,
yhje, flzfje, yeje
from ZY_BRJSMXK where jsxh=@jsxh --update by zwj 2003.12.5 取结算库信息
/*
select dxmdm, sum(zje) xmje, sum(round(zfdj*ypsl/ykxs,2)) zfje,
sum(round(yhdj*dwxs*ypsl/ykxs,2)) yhje, sum(flzfje) flzfje, sum(case when yexh>0 then zje else 0 end) yeje
from ZY_BRFYMXK where syxh=@syxh group by dxmdm
*/
end
if @@rowcount=0
begin
select "F","患者这段时间内没有发生费用,不用结算!"
return
end
if @jsfs=1 and isnull(@mxxh,'')<>''
begin
--mit , 2004-07-22,
select @zje2=@zje, @zfyje2=@zfyje, @yhje2=@yhje, @flzfje2=@flzfje
select @zje=sum(xmje), @zfyje=sum(zfje), @yhje=sum(yhje), @flzfje=sum(flzfje) from #fymxk
select @zje2=@zje2-@zje, @zfyje2=@zfyje2-@zfyje, @yhje2=@yhje2-@yhje, @flzfje2=@flzfje2-@flzfje
select @zje1=0, @zfyje1=0, @yhje1=0, @flzfje1=0, @sfje1=0
end
else if @jsfs=1 and @rqbz=1
begin
/*--modify by Wang Yi, 2003.09.29,
select @zje2=@zje, @zfyje2=@zfyje, @yhje2=@yhje, @flzfje2=@flzfje
select @zje=sum(xmje)-@zje1, @zfyje=sum(zfje)-@zfyje1, @yhje=sum(yhje)-@yhje1, @flzfje=sum(flzfje)-@flzfje1 from #fymxk
select @zje2=@zje2-@zje, @zfyje2=@zfyje2-@zfyje, @yhje2=@yhje2-@yhje, @flzfje2=@flzfje2-@flzfje
*/
--modify by Wang Yi, 2003.09.29,
select @zje2=@zje, @zfyje2=@zfyje, @yhje2=@yhje, @flzfje2=@flzfje
select @zje=sum(xmje)-@zje1, @zfyje=sum(zfje)-@zfyje1, @yhje=sum(yhje)-@yhje1, @flzfje=sum(flzfje)-@flzfje1 from #fymxk
select @zje2=@zje2-@zje, @zfyje2=@zfyje2-@zfyje, @yhje2=@yhje2-@yhje, @flzfje2=@flzfje2-@flzfje
end
else
begin
--正常结算置剩余金额和中途结算金额为0,不参与计算 zwj 2004.03.08
select @zje2=0, @zfyje2=0, @yhje2=0, @flzfje2=0
select @zje1=0, @zfyje1=0, @yhje1=0, @flzfje1=0, @sfje1=0
end
if @jsfs=1 and isnull(@mxxh,'')<>''
begin
--mit , 2004-07-22
insert into #fymxk1
select a.dxmdm, a.xmje, a.zfje, a.yhje, a.flzfje, a.yeje
from #fymxk a
if @@error<>0
begin
select "F","计算病人结算明细出错!"
return
end
end
else if @jsfs=1 and @rqbz=1
begin
/*select dxmdm, sum(xmje) xmje, sum(zfje) zfje, sum(yhje) yhje, sum(flzfje) flzfje, sum(yeje) yeje into #jsmxk1
from ZY_BRJSMXK a where exists(select 1 from ZY_BRJSK b where b.syxh=@syxh and b.jszt=1 and b.ybjszt=2 and b.jlzt=0 and a.jsxh=b.xh)
group by a.dxmdm
if @@error<>0
begin
select "F","计算病人结算明细出错!"
return
end
insert into #fymxk1
select a.dxmdm, a.xmje-isnull(b.xmje,0) xmje, a.zfje-isnull(b.zfje,0) zfje, a.yhje-isnull(b.yhje,0) yhje, a.flzfje-isnull(b.flzfje,0) flzfje, a.yeje-isnull(b.yeje,0) yeje
from #fymxk a, #jsmxk1 b where a.dxmdm*=b.dxmdm
if @@error<>0
begin
select "F","计算病人结算明细出错!"
return
end
*/
select dxmdm, sum(xmje) xmje, sum(zfje) zfje, sum(yhje) yhje, sum(flzfje) flzfje, sum(yeje) yeje into #jsmxk1
from ZY_BRJSMXK a where exists(select 1 from ZY_BRJSK b where b.syxh=@syxh and b.jszt=1 and b.ybjszt=2 and b.jlzt=0 and a.jsxh=b.xh)
group by a.dxmdm
if @@error<>0
begin
select "F","计算病人结算明细出错!"
return
end
insert into #fymxk1
select a.dxmdm, a.xmje-isnull(b.xmje,0) xmje, a.zfje-isnull(b.zfje,0) zfje, a.yhje-isnull(b.yhje,0) yhje, a.flzfje-isnull(b.flzfje,0) flzfje, a.yeje-isnull(b.yeje,0) yeje
from #fymxk a, #jsmxk1 b where a.dxmdm*=b.dxmdm
if @@error<>0
begin
select "F","计算病人结算明细出错!"
return
end
end
end