存储过程 insert
/*************************************************
**************************************************/
(
@ret int=-1 output,
@nHotelId int,
@nId int=-1 output,
@nCnmListId int,
@nCashId int,
@nPayValue decimal(18,2),
@tag int,
@nCshGroupId int=-1 output
)
as
begin
if dbo.F_GetOptionLock(@nHotelId)=1
begin
return
end
declare @cContent nvarchar(1000)
declare @nLogTypeId int
if @nCshGroupId<1
begin
exec P_GetGlobalId @nCshGroupId output
end
if @tag=1 --bill
begin
insert into C_BillCnmCsh(nHotelId,nBillCnmListId,nBillCashId,nPayValue,nCshGroupId)
values(@nHotelId,@nCnmListId,@nCashId,@nPayValue,@nCshGroupId)
set @nId=@@identity
-- update C_BillCash set nCshGroupId=@nCshGroupId where nId=@nCashId
-- update C_BillCnmList set nCshGroupId=@nCshGroupId where nId=@nCnmListId
-----------------------------------------------------
-------Begin Log-------------------------------------
-- set @cContent='新增主单付款明细:nId'+convert(varchar(20),@nId)+',金额:'+convert(varchar(20),@nPayValue)
-- set @nLogTypeId=[dbo].[F_GetLogTypeId_Bill]()
-- exec P_DoLog @ret output,@nHotelId,null,@cContent,'C_BillCnmCsh',null,null,null,null,null,@nLogTypeId
--2009-04-17
-------End Log---------------------------------------
-----------------------------------------------------
set @ret=1
end
else if @tag=2 --guest
begin
insert into C_GuestCnmCsh(nHotelId,nGuestCnmListId,nGuestCashId,nPayValue,nCshGroupId)
values(@nHotelId,@nCnmListId,@nCashId,@nPayValue,@nCshGroupId)
set @nId=@@identity
-- update C_GuestCash set nCshGroupId=@nCshGroupId where nId=@nCashId
-- update C_GuestCnmList set nCshGroupId=@nCshGroupId where nId=@nCnmListId
-----------------------------------------------------
-------Begin Log-------------------------------------
-- set @cContent='新增客单付款明细:nId'+convert(varchar(20),@nId)+',金额:'+convert(varchar(20),@nPayValue)
-- set @nLogTypeId=[dbo].[F_GetLogTypeId_Guest]()
-- exec P_DoLog @ret output,@nHotelId,null,@cContent,'C_GuestCnmCsh',null,null,null,null,null,@nLogTypeId
--2009-04-17
-------End Log---------------------------------------
-----------------------------------------------------
set @ret=1
end
end
set QUOTED_IDENTIFIER ON
go
ALTER proc [dbo].[P_InsertGuestCnmList]
(
@ret int=-1 output,
@nHotelId int,
@nGuestId int,
@nProductId int,
@nProductTypeId int,
@nCount decimal(18,2),
@nPrice decimal(18,2),
@nUserId int,
@cComputer nvarchar(50),
@cRemark nvarchar(4000),
@nJobTimeListId int,
@cOutBillCode nvarchar(50),
@tag int
)
/*************************************************
**************************************************/
as
begin
---- if dbo.F_GetOptionLock(@nHotelId)=1
---- begin
---- return
---- end
declare @cContent nvarchar(1000)
declare @nLogTypeId int,@nPkgListId int
declare @GuestCnmListnId int,@nBillId int,@ntargId int,@nCnmListId int
declare @cCnmSourceName nvarchar(10),@nConsumeKindId int,@cProductName nvarchar(50),
@nUnitId int,@cUnitName nvarchar(10),
----------------插入佣金值------------------------------------------------------------------------------------------------------------
@nCompanyId int,@nCompanyPrice decimal(18,2),@bIsCompanyPrice bit
select @nCompanyId=nPactId from C_Guest where nId=@nGuestId
select @nCompanyPrice=dbo.F_GetCompanyPrice(@nHotelId,@nCompanyId,@nProductId)
if @nCompanyPrice=-1
begin
set @bIsCompanyPrice=0
end
else
begin
set @bIsCompanyPrice=1
end
------------------------------------------------------------------
select @cCnmSourceName=cName from A_CnmSource where nId=1
if not exists(select 1 from C_Guest where nBillStateId in(1,3) and nHotelId=@nHotelId and nId=@nGuestId)
begin
set @ret=-1
return
end
if @tag=1
begin
select @nConsumeKindId=nConsumeKindId,@cProductName=cName,
@nUnitId=nUnitId,@cUnitName=cUnitName from B_Consume
where nId=@nProductId and nHotelId=@nHotelId
insert into C_GuestCnmList(nHotelId,cCnmSourceName,nGuestId,nConsumeListStateId,nCnmListTypeId,nProductTypeId,
nConsumeKindId,nProductId,cProductName,nCount,nUnitId,cUnitName,nPrice,nValue,nJobTimeListId,
dOptionTime,nUserId,cComputer,cRemark,cOutBillCode,bIsPackage,bIsOwn,IsCompanyPrice,nCompanyPrice)
values(@nHotelId,@cCnmSourceName,@nGuestId,1,1,@nProductTypeId,
@nConsumeKindId,@nProductId,@cProductName,@nCount,@nUnitId,@cUnitName,@nPrice,@nCount*@nPrice,@nJobTimeListId,
getdate(),@nUserId,@cComputer,@cRemark,@cOutBillCode,0,1,@bIsCompanyPrice,@nCompanyPrice)
set @GuestCnmListnId=@@identity
select @nBillId=nBillId from C_Guest where nId=@nGuestId
and nHotelId=@nHotelId
--处理自动转账(含转团帐)
if exists(select 1 from C_GuestAccount where nGuestId=@nGuestId
and nHotelId=@nHotelId and nConsumeKindId=@nConsumeKindId)
begin --转团帐
exec P_DoTransfer @ret output,2,1,@nGuestId,@nBillId,@GuestCnmListnId,
@nHotelId,@nUserId,@nJobTimeListId,@cComputer,@cRemark
end
else if exists(select 1 from dbo.C_G2BAccountTurn
where nHotelId=@nHotelId
and nSourceGuestId=@nGuestId and nConsumeKindId=@nConsumeKindId)
begin
select @ntargId=nTargetBillId from dbo.C_G2BAccountTurn
where nHotelId=@nHotelId
and nSourceGuestId=@nGuestId and nConsumeKindId=@nConsumeKindId
exec P_DoTransfer @ret output,2,1,@nGuestId,@ntargId,@GuestCnmListnId,
@nHotelId,@nUserId,@nJobTimeListId,@cComputer,@cRemark
end
else if exists(select 1 from dbo.C_G2GAccountTurn
where nHotelId=@nHotelId
and nSourceGuestId=@nGuestId and nConsumeKindId=@nConsumeKindId)
begin
select @ntargId=nTargetGuestId from dbo.C_G2GAccountTurn
where nHotelId=@nHotelId
and nSourceGuestId=@nGuestId and nConsumeKindId=@nConsumeKindId
exec P_DoTransfer @ret output,2,2,@nGuestId,@ntargId,@GuestCnmListnId,
@nHotelId,@nUserId,@nJobTimeListId,@cComputer,@cRemark
end
-----------------------------------------------------
-------Begin Log-------------------------------------
set @cContent='[收银入账] 消费 '+@cProductName+' '+convert(nvarchar(20),@nCount)+@cUnitName+',共计'+convert(nvarchar(50),@nCount*@nPrice)+'元'
-- set @cContent='新增客单消费明细:['+[dbo].[F_GetConsumeKindName](@nConsumeKindId)+'],金额'+convert(nvarchar(50),@nCount*@nPrice)
set @nLogTypeId=[dbo].[F_GetLogTypeId_Guest]()
exec P_DoLog @ret output,@nHotelId,@cComputer,@cContent,'C_GuestCnmList',@nUserId,null,@nGuestId,null,null,@nLogTypeId
--2009-04-17
-------End Log---------------------------------------
-----------------------------------------------------
set @ret=1
end
else if @tag=2
begin
begin tran
insert into C_GuestPkgList(cCnmSourceName,nGuestId,nConsumeListStateId,nCnmListTypeId,
nProductTypeId,nPackageId,cPackageName,nCount,nUnitId,cUnitName,nJobTimeListId,
dOptionTime,nUserId,cComputer,cRemark,nHotelId)
select @cCnmSourceName,@nGuestId,1,1,
nProductTypeId,@nProductId,cName,@nCount,nUnitId,cUnitName,@nJobTimeListId,
getdate(),@nUserId,@cComputer,@cRemark,@nHotelId
from B_Package where nId=@nProductId and nHotelId=@nHotelId
set @nPkgListId=@@identity
insert into C_GuestCnmList(nHotelId,cCnmSourceName,nGuestId,nConsumeListStateId,nCnmListTypeId,nProductTypeId,
nConsumeKindId,nProductId,cProductName,nCount,nUnitId,cUnitName,nPrice,nValue,nJobTimeListId,
dOptionTime,nUserId,cComputer,cRemark,cOutBillCode,bIsPackage,nPkgListId,bIsOwn)
select @nHotelId,@cCnmSourceName,@nGuestId,1,1,nProductTypeId,
nConsumeKindId,nId,cName,nCount*@nCount,nUnitId,cUnitName,nPrice,nCount*@nCount*nprice,@nJobTimeListId,
getdate(),@nUserId,@cComputer,@cRemark,@cOutBillCode,1,@nPkgListId,1
from dbo.V_PkgItm where nPackageId=@nProductId and bIsUse=1
--处理自动转账(含转团帐)
if exists(select 1 from C_GuestAccount where nGuestId=@nGuestId
and nHotelId=@nHotelId)
begin --转团帐
declare mycursor2 cursor for
select A.nId from C_GuestCnmList A
right join C_GuestAccount B On A.nGuestId=B.nGuestId
and A.nConsumeKindId=B.nConsumeKindId
where A.nConsumeListStateId=1 and A.nCnmListTypeId=1
and bIsPackage=1 and nPkgListId=@nPkgListId
and A.nGuestId=@nGuestId and A.nHotelId=@nHotelId
and B.nGuestId=@nGuestId and B.nHotelId=@nHotelId
open mycursor2
fetch mycursor2 into @nCnmListId
while @@fetch_status=0
begin
exec P_DoTransfer @ret output,2,1,@nGuestId,@nBillId,@nCnmListId,
@nHotelId,@nUserId,@nJobTimeListId,@cComputer,@cRemark
fetch mycursor2 into @nCnmListId
end
close mycursor2
deallocate mycursor2
end
else if exists(select 1 from dbo.C_G2BAccountTurn
where nHotelId=@nHotelId
and nSourceGuestId=@nGuestId)
begin
declare mycursor cursor for
select A.nId,nTargetBillId from C_GuestCnmList A
right join C_G2BAccountTurn B On A.nGuestId=B.nSourceGuestId and A.nConsumeKindId=B.nConsumeKindId
where A.nConsumeListStateId=1 and A.nCnmListTypeId=1
and bIsPackage=1 and nPkgListId=@nPkgListId
and A.nGuestId=@nGuestId and A.nHotelId=@nHotelId
open mycursor
fetch mycursor into @nCnmListId,@ntargId
while @@fetch_status=0
begin
exec P_DoTransfer @ret output,2,1,@nGuestId,@ntargId,@nCnmListId,
@nHotelId,@nUserId,@nJobTimeListId,@cComputer,@cRemark
fetch mycursor into @nCnmListId,@ntargId
end
close mycursor
deallocate mycursor
end
else if exists(select 1 from dbo.C_G2GAccountTurn
where nHotelId=@nHotelId
and nSourceGuestId=@nGuestId)
begin
declare mycursor1 cursor for
select A.nId,nTargetGuestId from C_GuestCnmList A
right join C_G2GAccountTurn B On A.nGuestId=B.nSourceGuestId and A.nConsumeKindId=B.nConsumeKindId
where A.nConsumeListStateId=1 and A.nCnmListTypeId=1
and bIsPackage=1 and nPkgListId=@nPkgListId
and A.nGuestId=@nGuestId and A.nHotelId=@nHotelId
open mycursor1
fetch mycursor1 into @nCnmListId,@ntargId
while @@fetch_status=0
begin
exec P_DoTransfer @ret output,2,2,@nGuestId,@ntargId,@nCnmListId,
@nHotelId,@nUserId,@nJobTimeListId,@cComputer,@cRemark
fetch mycursor1 into @nCnmListId,@ntargId
end
close mycursor1
deallocate mycursor1
end
-----------------------------------------------------
-------Begin Log-------------------------------------
set @cContent='日志待补充'
-- set @cContent='新增住客套餐消费项:nPackageId'+convert(varchar(20),@nProductId)
set @nLogTypeId=[dbo].[F_GetLogTypeId_Guest]()
exec P_DoLog @ret output,@nHotelId,@cComputer,@cContent,'C_GuestCnmList',@nUserId,null,@nGuestId,null,null,@nLogTypeId
--2009-04-17
-------End Log---------------------------------------
-----------------------------------------------------
set @ret=1
commit tran
end
else
begin
set @ret=-1
end
end
转载于:https://www.cnblogs.com/callbin/archive/2009/12/29/1634936.html
存储过程 insert相关推荐
- 自动生成存储过程的脚本
如果一个表的字段非常的多的话,平时写存储过程,是不是很耗费时间呢,盯着眼睛痛,有了自动生成代码程序,只需F5一下就好了<( ̄︶ ̄)> --自动生成存储过程Update --要使用的数据库名 ...
- .Net执行SQL/存储过程之易用轻量工具
支持.Net/.Net Core/.Net Framework,可以部署在Docker, Windows, Linux, Mac. 由于该工具近来被广东省数个公司2B项目采用,且表现稳定,得到良好验证 ...
- Entity Framework 存储过程---新增、更新、删除
在EF中,各个实体的插入.更新和删除也都通过使用存储过程来完成,以便提高点性能.这个类似于数据集.其步骤是:先定义存储过程,然后在VS的可视化设计器,设置存储过程映射即可. 下面,以为Supplier ...
- Entity Framework 学习中级篇4—存储过程(下)
在EF中,各个实体的插入.更新和删除也都通过使用存储过程来完成,以便提高点性能.这个类似于数据集.其步骤是:先定义存储过程,然后在VS的可视化设计器,设置存储过程映射即可. 下面,以为Supplier ...
- Entity Framework 学习中级篇4—存储过程(下)(转)
在EF中,各个实体的插入.更新和删除也都通过使用存储过程来完成,以便提高点性能.这个类似于数据集.其步骤是:先定义存储过程,然后在VS的可视化设计器,设置存储过程映射即可. 下面,以为Supplier ...
- 创建用户赋权限_MySQL实战第84篇:MySQL数据库添加用户和赋权限,在8.0版本!
欢迎来到MySQL实战第84篇,修炼MySQL,让我们更加的自信! [查看数据库] [使用mysql数据库] [创建新用户:mytest,密码111222] create user mytest id ...
- 浅谈.Net版(C#)的CMP模式
商城上线快2.3个月了,一直都懒得写点东西,在加上杂七杂八的事情也比较忙,所以都没有把这个系统当时做的整个架构思绪整理清,昨天才从深圳完了两天回来,怎感觉是要做的事来着.刚开始接触CMP模式的时候也是 ...
- NetTiers模板中各个选项的一些解释
名称 ChooseSourceDatabase 选择数据库 MappingFile Mapping文件位置(会根据output目录自动更改,不需要设置) OutputDirectory 文件输出目录 ...
- 数据库原理与应用课程知识点
数据库原理与应用课程知识点 文章目录 数据库原理与应用课程知识点 **第一章 绪论** 数据.数据库.数据库管理系统.数据库系统的概念 数据管理技术发展的三个阶段及各阶段的优缺点 概念模型中的基本术语 ...
最新文章
- 滴滴员工抱怨女朋友要求自己上进!工资必须比她高一半!决定分手却不直说!对女朋友冷暴力等她自己走!...
- 适用于Android的OpenSL ES指南-OpenSL ES的Android扩展
- 【Android应用开发】分享一个录制 Android 屏幕 gif 格式的小技巧
- Oracle启动和停止的方式详解
- e300氛围灯哪里调节_奥迪Q5L安装原厂32色20灯源氛围灯
- SQL语句中的select高级用法
- 强化学习DQN算法实战之CartPole
- Mapreduce的分区—Partitioner
- 抛开百度、知乎等都找不到连接不上服务器远程桌面的原因
- 51nod1433--简单数学
- sqlite使用手册
- 教育平台在线,教育平台源码 类似eduline教育平台系统源码下载
- linux命令详解词典pdf,[计算机]linux命令详解词典
- 0x00007FFC4480532C(opencv_world310.dll)处(位于opencv-024.exe中)引发的异常:OxC0000005:读取位置0xFFFFFFFFFF时发生访问冲突
- zendstudio php6.5,ZendStudio13.6配置composer.phar和中文镜像、如何更新php项目依赖组件方法...
- 解决Kafka-1194问题
- Python 在线电子零售公司销售数据(Online Retail | Kaggle)关联规则分析(Apriori算法)
- 网上买包包首选的3个网站(必看的3个包包网站)
- 在线电子书阅读微信小程序 毕业设计(5)用户登录注册
- 空间申请(malloc)与释放(free)——C语言