# t_sql

执行:
---
INSERT INTO[t_sys_soft]([版本号],[系统],[版本1],[版本2],[版本3],[软件名称]) VALUES('7.22.0829', NULL, '7', '22', '0829', 'd7')
---
GO

delete From user_authority_info where GID='B64E8500-E56B-40D0-BA51-96FB37471C60'
insert Into user_authority_info (GID,NAME,DESCRIPTION,MODULEURL,ISALL,ISCOMPANY,ISDEPT,ISPERSON,CREATEUSER
,CREATETIME,MODIFIEDUSER,MODIFIEDTIME,ISDELETE) values(
'B64E8500-E56B-40D0-BA51-96FB37471C60','modOp_BLISSUESP','特殊放单申请','Mvcshipping/MsOp_BLISSUE/Index_SP',0,0,0,0,'1BEC90E1-9780-472F-90C2-0C6390C044A4','2022-08-03 10:07:45.173','1BEC90E1-9780-472F-90C2-0C6390C044A4',getdate(),0)


执行:
---
INSERT INTO[t_sys_soft]([版本号],[系统],[版本1],[版本2],[版本3],[软件名称]) VALUES('7.22.0830', NULL, '7', '22', '0830', 'd7')
---
GO

alter table op_blissuelist add AUDITOR varchar(50) null
GO

ALTER VIEW [dbo].[VW_user]
AS
SELECT     ub.USERID, u.CODENAME, u.SHOWNAME, uc.COMPANYID, c.NAME AS companyname, sd.GID AS deptgid, sd.DEPTNAME, sd.DEPTNO, ub.EMAIL1, ub.mailsign, 
                      u.WeChatAccount,
  (select top 1 value from user_userattribute where userid=u.GID and attributeid='3C91140E-6FB6-4B5A-B5AB-30E59E3CBBED' ) ISSALEMAN
  ,u.SHOWNAME UserName,u.CODENAME+'-'+u.SHOWNAME CodeAndName
FROM         dbo.user_baseinfo AS ub 
LEFT OUTER JOIN dbo.user_company AS uc ON uc.USERID = ub.USERID 
LEFT OUTER JOIN dbo.sys_dept AS sd ON sd.DEPTNAME = ub.DEPTNAME AND sd.LINKID = uc.COMPANYID 
LEFT OUTER JOIN dbo.[user] AS u ON u.GID = ub.USERID 
LEFT OUTER JOIN dbo.company AS c ON c.GID = uc.COMPANYID
WHERE     (u.ISDISABLE = 0) AND (u.ISDELETED = 0)


GO


执行:
---
INSERT INTO[t_sys_soft]([版本号],[系统],[版本1],[版本2],[版本3],[软件名称]) VALUES('7.22.0831', NULL, '7', '22', '0831', 'd7')
---
GO


alter table crm_aireorder add WAREHOUSINGNO varchar(200) null


alter table op_aire add WAREHOUSINGNO varchar(200) null


执行:
---
INSERT INTO[t_sys_soft]([版本号],[系统],[版本1],[版本2],[版本3],[软件名称]) VALUES('7.22.0901', NULL, '7', '22', '0901', 'd7')
---
GO




ALTER PROCEDURE [dbo].[p_update_recvapplycation]
@con_no varchar(100)
 AS
DECLARE
@RMBAMOUNT [numeric](18, 4),
@RMBDOAMOUNT [numeric](18, 4),
@USDAMOUNT [numeric](18, 4),
@USDDOAMOUNT [numeric](18, 4),
@AMOUNTCOUNT int,
@DOAMOUNTCOUNT int,
@COUNT int


select 
@RMBAMOUNT=0,
@RMBDOAMOUNT=0,
@USDAMOUNT=0,
@USDDOAMOUNT=0

SELECT 
@RMBAMOUNT=isnull(SUM(CASE WHEN CURRENCY='RMB' THEN (CASE FEETYPE WHEN 1 THEN AMOUNT ELSE -AMOUNT END) ELSE 0 END),0),
@RMBDOAMOUNT=isnull(SUM(CASE WHEN CURRENCY='RMB' THEN (CASE FEETYPE WHEN 1 THEN DOAMOUNT ELSE -DOAMOUNT END) ELSE 0 END),0),
@USDAMOUNT=isnull(SUM(CASE WHEN CURRENCY<>'RMB' THEN (CASE FEETYPE WHEN 1 THEN AMOUNT ELSE -AMOUNT END) ELSE 0 END),0),
@USDDOAMOUNT=isnull(SUM(CASE WHEN CURRENCY<>'RMB' THEN (CASE FEETYPE WHEN 1 THEN DOAMOUNT ELSE -DOAMOUNT END) ELSE 0 END),0)
FROM ch_fee_do
WHERE BILLNO=@con_no and CATEGORY=5 

SELECT 
@COUNT=COUNT(*)
FROM ch_fee_do
WHERE BILLNO=@con_no and CATEGORY=5 
SELECT 
@DOAMOUNTCOUNT=COUNT(*)
FROM ch_fee_do
WHERE BILLNO=@con_no and CATEGORY=5 and AMOUNT=DOAMOUNT
SELECT 
@AMOUNTCOUNT=COUNT(*)
FROM ch_fee_do
WHERE BILLNO=@con_no and CATEGORY=5 and DOAMOUNT=0

UPDATE ch_fee_recvapplication SET AMOUNTRMB=@RMBAMOUNT,SETTLERMB=@RMBDOAMOUNT,AMOUNTUSD=@USDAMOUNT,SETTLEUSD=@USDDOAMOUNT
,BILLSTATUS=( CASE WHEN @DOAMOUNTCOUNT=@COUNT 
THEN 4 ELSE CASE WHEN @AMOUNTCOUNT=@COUNT THEN CASE WHEN BILLSTATUS IN (4,5) THEN 2 ELSE BILLSTATUS END ELSE 5 END END ) WHERE BILLNO=@con_no



GO


执行:
---
INSERT INTO[t_sys_soft]([版本号],[系统],[版本1],[版本2],[版本3],[软件名称]) VALUES('7.22.0902', NULL, '7', '22', '0902', 'd7')
---
GO



ALTER view [dbo].[v_op_bill_gain_shen]
as    
 SELECT B.BSNO, B.PARENTID,B.OPLB,B.OPTYPE,B.OPLBNAME, B.BSTYPE,B.CUSTOMERNAME, B.CUSTNO, B.MBLNO, B.HBLNO,B.VESSEL, B.VOYNO, B.INPUTBY, B.CREATETIME, B.BSSTATUS, B.SALE, B.OP, B.DOC,
 case B.ETD when '1900-01-01 00:00:00.000' then '' else CONVERT(varchar(100), B.ETD,23) end as ETD
,case B.OPDATE when '1900-01-01 00:00:00.000' then '' else CONVERT(varchar(100), B.OPDATE,23) end as OPDATE,B.ENTERP
,case B.CUSTOMDATE when '1900-01-01 00:00:00.000' then '' else CONVERT(varchar(100), B.CUSTOMDATE,23) end as CUSTOMDATE
,case B.FEESTATUS when 1 then '锁定' else '未锁定' end as FEESTATUSREF,B.BLFRT,B.BSSOURCEDETAIL
,B.CUSTSERVICE, B.PORTLOAD, B.PORTDISCHARGE, B.CUSTOMNO, B.ACCDATE,B.CARRIER, B.BSSOURCE, B.LANE, B.FORWARDER,B.NETWEIGHT,B.KGS,B.TEU,B.CNTRTOTAL,B.CORPID
,B.CNTR1,B.CNTR2,B.CNTR3,B.CNTR4,B.CNTR5,B.CNTR6,B.CNTR7,B.CNTR8,B.CNTR9,B.CNTR10,B.OTCNTR,B.TRADETYPE,B.GOODSNAME,B.FEESTATUS
,G.RMBDR,G.RMBCR,G.STLRMBDR,G.STLRMBCR,G.USDDR,G.USDCR,G.STLUSDDR,G.STLUSDCR,G.OTDR,G.OTCR,G.STLOTDR,G.STLOTCR,G.TTLDR,G.TTLCR,G.STLTTLDR,G.STLTTLCR
,G.USDDR-G.USDCR AS USDPROFIT,G.RMBDR-G.RMBCR AS RMBPROFIT,G.OTDR-G.OTCR AS OTPROFIT,G.TTLDR-G.TTLCR AS TTLPROFIT 
, (CASE WHEN (G.TTLCR)= 0 THEN '无法计算' ELSE ltrim(str((G.TTLDR-G.TTLCR) / (G.TTLCR) * 100, 10, 2)) + '%' END) AS PROFITRATE
,G.RMBDR-G.STLRMBDR AS RMBNODR,G.USDDR-G.STLUSDDR AS USDNODR,G.OTDR-G.STLOTDR AS OTNODR,G.TTLDR-G.STLTTLDR AS TTLNODR
,G.RMBCR-G.STLRMBCR AS RMBNOCR,G.USDCR-G.STLUSDCR AS USDNOCR,G.OTCR-G.STLOTCR AS OTNOCR,G.TTLCR-G.STLTTLCR AS TTLNOCR
,(select dbo.trimdate(stldate) from v_op_bs where bsno=b.bsno) stldate
,B.BLISSUESTATUS
 FROM V_OP_BILL B 
LEFT JOIN v_op_gain_sum_shen G ON (G.BSNO=B.BSNO)

GO



ALTER view [dbo].[v_op_bill_gain]
as    
 SELECT B.BSNO,B.PARENTID, B.OPLB,B.OPTYPE,B.OPLBNAME, B.BSTYPE,B.CUSTOMERNAME, B.CUSTNO, B.MBLNO, B.HBLNO,B.VESSEL, B.VOYNO, B.INPUTBY, B.CREATETIME, B.BSSTATUS, B.SALE, B.OP, B.DOC,
 case B.ETD when '1900-01-01 00:00:00.000' then '' else CONVERT(varchar(100), B.ETD,23) end as ETD
,case B.OPDATE when '1900-01-01 00:00:00.000' then '' else CONVERT(varchar(100), B.OPDATE,23) end as OPDATE,B.ENTERP
,case B.CUSTOMDATE when '1900-01-01 00:00:00.000' then '' else CONVERT(varchar(100), B.CUSTOMDATE,23) end as CUSTOMDATE
,case B.FEESTATUS when 1 then '锁定' else '未锁定' end as FEESTATUSREF,B.BLFRT,B.BSSOURCEDETAIL
,B.CUSTSERVICE, B.PORTLOAD, B.PORTDISCHARGE, B.CUSTOMNO, B.ACCDATE,B.CARRIER, B.BSSOURCE, B.LANE, B.FORWARDER,B.NETWEIGHT,B.KGS,B.TEU,B.CNTRTOTAL,B.CORPID,B.SALECORPID
,B.CNTR1,B.CNTR2,B.CNTR3,B.CNTR4,B.CNTR5,B.CNTR6,B.CNTR7,B.CNTR8,B.CNTR9,B.CNTR10,B.OTCNTR,B.TRADETYPE,B.GOODSNAME,B.FEESTATUS
,G.RMBDR,G.RMBCR,G.STLRMBDR,G.STLRMBCR,G.USDDR,G.USDCR,G.STLUSDDR,G.STLUSDCR,G.OTDR,G.OTCR,G.STLOTDR,G.STLOTCR,G.TTLDR,G.TTLCR,G.STLTTLDR,G.STLTTLCR
,G.USDDR-G.USDCR AS USDPROFIT,G.RMBDR-G.RMBCR AS RMBPROFIT,G.OTDR-G.OTCR AS OTPROFIT,G.TTLDR-G.TTLCR AS TTLPROFIT,G.NOTAXTTLDR-G.NOTAXTTLCR AS NOTAXTTLPROFIT 
, (CASE WHEN (G.TTLCR)= 0 THEN '无法计算' ELSE ltrim(str((G.TTLDR-G.TTLCR) / (G.TTLCR) * 100, 10, 2)) + '%' END) AS PROFITRATE
,G.RMBDR-G.STLRMBDR AS RMBNODR,G.USDDR-G.STLUSDDR AS USDNODR,G.OTDR-G.STLOTDR AS OTNODR,G.TTLDR-G.STLTTLDR AS TTLNODR
,G.RMBCR-G.STLRMBCR AS RMBNOCR,G.USDCR-G.STLUSDCR AS USDNOCR,G.OTCR-G.STLOTCR AS OTNOCR,G.TTLCR-G.STLTTLCR AS TTLNOCR
,G.NOACCTAXTTLDR-G.NOACCTAXTTLCR AS NOACCTAXTTLPROFIT
,B.stldate
,b.STLNAME,B.DELIVERYDATE,B.BLISSUESTATUS
 FROM V_OP_BILL B 
LEFT JOIN v_op_gain_sum G ON (G.BSNO=B.BSNO)



GO


ALTER view [dbo].[v_op_bill_cust_gain_shen]
as    
 SELECT B.BSNO, B.OPLB,B.OPTYPE,B.OPLBNAME, B.BSTYPE,B.CUSTOMERNAME, B.CUSTNO, B.MBLNO, B.HBLNO,B.VESSEL, B.VOYNO, B.INPUTBY, B.CREATETIME, B.BSSTATUS, B.SALE, B.OP, B.DOC,
 case B.ETD when '1900-01-01 00:00:00.000' then '' else CONVERT(varchar(100), B.ETD,23) end as ETD
,case B.OPDATE when '1900-01-01 00:00:00.000' then '' else CONVERT(varchar(100), B.OPDATE,23) end as OPDATE,B.ENTERP
,case B.CUSTOMDATE when '1900-01-01 00:00:00.000' then '' else CONVERT(varchar(100), B.CUSTOMDATE,23) end as CUSTOMDATE
,case B.FEESTATUS when 1 then '锁定' else '未锁定' end as FEESTATUSREF,B.BLFRT,B.BSSOURCEDETAIL
,B.CUSTSERVICE, B.PORTLOAD, B.PORTDISCHARGE, B.CUSTOMNO, B.ACCDATE,B.CARRIER, B.BSSOURCE, B.LANE, B.FORWARDER,B.NETWEIGHT,B.KGS,B.TEU,B.CNTRTOTAL,B.CORPID
,B.CNTR1,B.CNTR2,B.CNTR3,B.CNTR4,B.CNTR5,B.CNTR6,B.CNTR7,B.CNTR8,B.CNTR9,B.CNTR10,B.OTCNTR,B.TRADETYPE,B.GOODSNAME,B.FEESTATUS
,G.RMBDR,G.RMBCR,G.STLRMBDR,G.STLRMBCR,G.USDDR,G.USDCR,G.STLUSDDR,G.STLUSDCR,G.OTDR,G.OTCR,G.STLOTDR,G.STLOTCR,G.TTLDR,G.TTLCR,G.STLTTLDR,G.STLTTLCR
,G.USDDR-G.USDCR AS USDPROFIT,G.RMBDR-G.RMBCR AS RMBPROFIT,G.OTDR-G.OTCR AS OTPROFIT,G.TTLDR-G.TTLCR AS TTLPROFIT 
, (CASE WHEN (G.TTLCR)= 0 THEN '无法计算' ELSE ltrim(str((G.TTLDR-G.TTLCR) / (G.TTLCR) * 100, 10, 2)) + '%' END) AS PROFITRATE
,G.RMBDR-G.STLRMBDR AS RMBNODR,G.USDDR-G.STLUSDDR AS USDNODR,G.OTDR-G.STLOTDR AS OTNODR,G.TTLDR-G.STLTTLDR AS TTLNODR
,G.RMBCR-G.STLRMBCR AS RMBNOCR,G.USDCR-G.STLUSDCR AS USDNOCR,G.OTCR-G.STLOTCR AS OTNOCR,G.TTLCR-G.STLTTLCR AS TTLNOCR
,b.stldate,g.CUSTOMERNAME CUSTNAME,B.BLISSUESTATUS
 FROM v_op_gain_cust_sum_shen G
LEFT JOIN v_op_bill b ON (b.BSNO=G.BSNO)


GO



ALTER view [dbo].[v_op_bill_cust_gain]
as    
 SELECT B.BSNO, B.OPLB,B.OPTYPE,B.OPLBNAME, B.BSTYPE,B.CUSTOMERNAME, B.CUSTNO, B.MBLNO, B.HBLNO,B.VESSEL, B.VOYNO, B.INPUTBY, B.CREATETIME, B.BSSTATUS, B.SALE, B.OP, B.DOC,
 case B.ETD when '1900-01-01 00:00:00.000' then '' else CONVERT(varchar(100), B.ETD,23) end as ETD
,case B.OPDATE when '1900-01-01 00:00:00.000' then '' else CONVERT(varchar(100), B.OPDATE,23) end as OPDATE,B.ENTERP
,case B.CUSTOMDATE when '1900-01-01 00:00:00.000' then '' else CONVERT(varchar(100), B.CUSTOMDATE,23) end as CUSTOMDATE
,case B.FEESTATUS when 1 then '锁定' else '未锁定' end as FEESTATUSREF,B.BLFRT,B.BSSOURCEDETAIL
,B.CUSTSERVICE, B.PORTLOAD, B.PORTDISCHARGE, B.CUSTOMNO, B.ACCDATE,B.CARRIER, B.BSSOURCE, B.LANE, B.FORWARDER,B.NETWEIGHT,B.KGS,B.TEU,B.CNTRTOTAL,B.CORPID
,B.CNTR1,B.CNTR2,B.CNTR3,B.CNTR4,B.CNTR5,B.CNTR6,B.CNTR7,B.CNTR8,B.CNTR9,B.CNTR10,B.OTCNTR,B.TRADETYPE,B.GOODSNAME,B.FEESTATUS
,G.RMBDR,G.RMBCR,G.STLRMBDR,G.STLRMBCR,G.USDDR,G.USDCR,G.STLUSDDR,G.STLUSDCR,G.OTDR,G.OTCR,G.STLOTDR,G.STLOTCR,G.TTLDR,G.TTLCR,G.STLTTLDR,G.STLTTLCR
,G.USDDR-G.USDCR AS USDPROFIT,G.RMBDR-G.RMBCR AS RMBPROFIT,G.OTDR-G.OTCR AS OTPROFIT,G.TTLDR-G.TTLCR AS TTLPROFIT 
, (CASE WHEN (G.TTLCR)= 0 THEN '无法计算' ELSE ltrim(str((G.TTLDR-G.TTLCR) / (G.TTLCR) * 100, 10, 2)) + '%' END) AS PROFITRATE
,G.RMBDR-G.STLRMBDR AS RMBNODR,G.USDDR-G.STLUSDDR AS USDNODR,G.OTDR-G.STLOTDR AS OTNODR,G.TTLDR-G.STLTTLDR AS TTLNODR
,G.RMBCR-G.STLRMBCR AS RMBNOCR,G.USDCR-G.STLUSDCR AS USDNOCR,G.OTCR-G.STLOTCR AS OTNOCR,G.TTLCR-G.STLTTLCR AS TTLNOCR
,b.stldate,g.CUSTOMERNAME CUSTNAME,B.BLISSUESTATUS
 FROM v_op_gain_cust_sum G
LEFT JOIN v_op_bill b ON (b.BSNO=G.BSNO)


GO


执行:
---
INSERT INTO[t_sys_soft]([版本号],[系统],[版本1],[版本2],[版本3],[软件名称]) VALUES('7.22.0903', NULL, '7', '22', '0903', 'd7')
---
GO

/****** Object:  StoredProcedure [dbo].[sSysGetBillNo_new]    Script Date: 2022/9/5 11:33:10 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO



ALTER  PROCEDURE [dbo].[sSysGetBillNo_new]
( @ps_BillType varchar(4),
  @ps_OrgCode varchar(100)='',
  @ps_EmpCode varchar(100)='',
  @ps_Date varchar(10)='',
  @ps_bshead varchar(20)='',
  @ps_BillNo varchar(20) output,
  @ps_RefBillNo varchar(20)=Null  --这个字段暂时没有使用
)
--WITH ENCRYPTION
AS
declare
	@vs_TmpBillNo varchar(20),
	@vs_IsUpdate varchar(1),
	@vi_ID     numeric(27,0),
	@vi_ID_A   numeric(27,0),
	@vi_ID_B   numeric(27,0),
	@vi_Times    integer,
	@vi_DelaySec integer,
	@vs_HeadTbl  varchar(100),
	@vs_NowDate  varchar(10),
	@vs_IsPrefix varchar(100),
	@vi_PrefixLen integer,
	@vs_PrefixNo varchar(100),
	@vs_IsDate varchar(100),
	@vi_DateLen integer,
	@vs_DateFmt  varchar(100),
	@vi_SerialLen integer,
	@vs_YearNo varchar(100),
	@vs_MonthNo varchar(100),
	@vs_DayNo varchar(100),
	@vs_IsOrgPrefix varchar(100),
	@vs_IsEmpPrefix varchar(100),	
	@vi_ii        int,
	@vi_MaxSerial integer,
	@vs_dateNo varchar(10),
	@vi_BillNoLength       int,
	@vi_BillHeadLength       int,
	@vs_BanksHead	varchar(10),
	@BsNo int
Begin
/*=================初始化变量=================*/
	Set @vs_IsUpdate='0'
	Set @ps_BillNo=null
	Set @vs_TmpBillNo=''
	if @ps_Date='' begin
	  Set @vs_NowDate=convert(varchar(10),getdate(),120)
	end else 
	  Set  @vs_NowDate=left(@ps_Date,10)

  /*	  update sys_no set ISUSE=1 where ISUSE=0 and BSNO in (select custno from v_op_bill)*/
	
/*=================取得单据号结构=================*/
	If not exists(select BillCode from tSysBillType where BillCode=@ps_BillType)
	Begin
		return(-1)
	End
	
	Select @vs_IsPrefix=IsPrefix,@vi_PrefixLen=PrefixLen,@vs_PrefixNo=PrefixNo,
		   @vs_IsDate=IsDate,@vs_DateFmt=DateFmt,@vi_SerialLen=SerialLen,
	       @vs_YearNo=IsNull(YearNo,''),@vs_MonthNo=IsNull(MonthNo,''),@vs_DayNo=IsNull(DayNo,''),
	       @vi_MaxSerial=MaxSerial,@vs_HeadTbl=IsNull(BillHeadTbl,''),
	       @vs_IsOrgPrefix=IsOrgPrefix,@vs_IsEmpPrefix=IsEmpPrefix
	  from tSysBillType
	  where BillCode=@ps_BillType	    
	
/*=================如果要分组织生成（ww）=================*/
	if @vs_IsOrgPrefix='1' 
	begin
	  set @vs_HeadTbl = @vs_HeadTbl + '_' + @ps_OrgCode;
	end

	if @vs_IsEmpPrefix='1' 
	begin
	  set @vs_HeadTbl = @vs_HeadTbl + '_' + @ps_EmpCode;
	end
	If @vi_MaxSerial=0 Set @vi_MaxSerial=1	
/*=================更新年月日=================*/
	If @vs_IsDate='1' and
		( (@vs_DateFmt in ('YYYYMMDD','YYMMDD') and @vs_NowDate<>@vs_YearNo+'-'+@vs_MonthNo+'-'+@vs_DayNo) or
		(@vs_DateFmt in ('YYYYMM','YYMM') and Left(@vs_NowDate,7)<>@vs_YearNo+'-'+@vs_MonthNo) or
		(@vs_DateFmt in ('YYYY','YY') and Left(@vs_NowDate,4)<>@vs_YearNo)
	)
	Begin  --更新并锁定表tSysBillType
		Set @vs_IsUpdate='1'
		
		
		Set @vs_YearNo=left(@vs_NowDate,4)
		Set @vs_DayNo=right(@vs_NowDate,2)
		Set @vs_MonthNo=substring(@vs_NowDate,6,2)

	End
	

if (@ps_bshead<>'')	begin
  set @vs_TmpBillNo=@vs_TmpBillNo+UPPER(@ps_bshead)
end

/*=================取得数据库标志=================*/
	--  Select @vs_TmpBillNo=IsNull(DBID,'0000') from tComDataBase where isself='1'
	
/*=================设置分公司前缀=================*/    
	if @vs_IsOrgPrefix='1'
	begin
	  select @vs_BanksHead=BANKSHEAD
	    from company
	   where CODENAME=@ps_OrgCode;
	   
	  set @vs_TmpBillNo=@vs_TmpBillNo+UPPER(@vs_BanksHead)
	end
	

	
/*=================取得前缀=================*/
	if (@vs_IsPrefix='1' and @vi_PrefixLen>0 and @vs_PrefixNo<>'')
		Set @vs_TmpBillNo=@vs_TmpBillNo+substring(@vs_PrefixNo,1,@vi_PrefixLen)
		
	if @vs_IsEmpPrefix='1' 
	begin
	  select @vs_BanksHead=NOCODE
	    from [USER]
	   where CODENAME=@ps_EmpCode;
	  set @vs_TmpBillNo =@vs_TmpBillNo+UPPER(@vs_BanksHead);
	end			
		
	
/*=================取得年月日=================*/
	if @vs_IsDate='1'
	begin
		If @vs_DateFmt='YYYYMMDD'
			Set @vs_TmpBillNo=@vs_TmpBillNo+@vs_YearNo+@vs_MonthNo+@vs_DayNo
		Else If @vs_DateFmt='YYMMDD'
			Set @vs_TmpBillNo=@vs_TmpBillNo+Right(@vs_YearNo,2)+@vs_MonthNo+@vs_DayNo
		Else If @vs_DateFmt='YYYYMM'
			Set @vs_TmpBillNo=@vs_TmpBillNo+@vs_YearNo+@vs_MonthNo
		Else If @vs_DateFmt='YYMM'
			Set @vs_TmpBillNo=@vs_TmpBillNo+Right(@vs_YearNo,2)+@vs_MonthNo
		Else If @vs_DateFmt='YYYY'
			Set @vs_TmpBillNo=@vs_TmpBillNo+@vs_YearNo
		Else If @vs_DateFmt='YY'
			Set @vs_TmpBillNo=@vs_TmpBillNo+right(@vs_YearNo,2)
	End
	
/*=================目前单据号最大为 20，加上分公司后可能超过20,需要特殊处理=================*/	
	set @vi_BillHeadLength=LEN(@vs_TmpBillNo)
	set @vi_BillNoLength=20-@vi_BillHeadLength
	if @vi_SerialLen > @vi_BillNoLength
	   set @vi_SerialLen=@vi_BillNoLength
	   
 if isnull((select top 1 BSNO from sys_no where ISUSE=0 and (substring (BSNO,1,@vi_BillHeadLength) =@vs_TmpBillNo) and (LEN(BSNO)=(@vi_SerialLen+@vi_BillHeadLength))),'1')='1' 
  begin
      if (select count(ID) from sys_wtno where HEADSTR=@vs_TmpBillNo and NOTYPE=@ps_BillType)=0
      begin
        select @BsNo=1
        insert sys_wtno ( HEADSTR, MAXNO,NOTYPE) values (@vs_TmpBillNo,1,@ps_BillType)
      end
      else
      begin
        select @BsNo =1+(select MAXNO from sys_wtno where HEADSTR=@vs_TmpBillNo and NOTYPE=@ps_BillType)
        update sys_wtno set MAXNO=@BsNo where HEADSTR=@vs_TmpBillNo and NOTYPE=@ps_BillType
      end	
	Set @vs_TmpBillNo=@vs_TmpBillNo+right('00000000000000000000'+Cast(@BsNo as varchar(100)),@vi_SerialLen)
	Set @ps_BillNo=(select REPLACE( @vs_TmpBillNo,'-',''))
	insert sys_no (BSNO, ISUSE) values (@ps_BillNo,1)
  end
  else
  begin
    select @vs_TmpBillNo=(select top 1 BSNO from sys_no where ISUSE=0 and (substring (BSNO,1,@vi_BillHeadLength) =@vs_TmpBillNo) and (LEN(BSNO)=(@vi_SerialLen+@vi_BillHeadLength)))
    Set @ps_BillNo=(select REPLACE( @vs_TmpBillNo,'-',''))
    update sys_no set ISUSE=1 where BSNO=@ps_BillNo
  end	   	   
	   
	   
  select @ps_BillNo as BillNo
End



GO


执行:
---
INSERT INTO[t_sys_soft]([版本号],[系统],[版本1],[版本2],[版本3],[软件名称]) VALUES('7.22.0904', NULL, '7', '22', '0904', 'd7')
---
GO


insert into tSysEnumValue (LANGID, ENUMTYPEID, ENUMVALUEID, ENUMVALUENAME, ISDEFAULT, DISPINDEX, VERNO)
    values (0, 97019, '43', '空运出口销售订舱', '0', 43, '1.00');  
GO


执行:
---
INSERT INTO[t_sys_soft]([版本号],[系统],[版本1],[版本2],[版本3],[软件名称]) VALUES('7.22.0905', NULL, '7', '22', '0905', 'd7')
---
GO

alter table ch_fee_payapplication add IsReplacePayment bit null
GO

alter table ch_fee_payapplication add ReplacePaymentStatus varchar(20) null
GO

alter table ch_fee_payapplication add ReplacePaymentCORPID varchar(50) null
GO

alter table ch_fee_payapplication add ReplacePaymentOPNAME varchar(30) null
GO

alter table ch_fee_payapplication add ReplacePaymentOPTIME Datetime null
GO


