# 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


执行:
---
INSERT INTO[t_sys_soft]([版本号],[系统],[版本1],[版本2],[版本3],[软件名称]) VALUES('7.22.0906', NULL, '7', '22', '0906', '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 @COUNT=0 THEN 1 ELSE CASE WHEN @DOAMOUNTCOUNT=@COUNT 
THEN 4 ELSE CASE WHEN @AMOUNTCOUNT=@COUNT THEN CASE WHEN BILLSTATUS IN (4,5) THEN 0 ELSE BILLSTATUS END ELSE 5 END END END ) WHERE BILLNO=@con_no



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(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(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.0916', NULL, '7', '22', '0916', 'd7')
---
GO


alter table op_blissuelist add SALECORPID varchar(50) null

update op_blissuelist set SALECORPID = (select COMPANYID from vw_user where SHOWNAME=op_blissuelist.SALE)


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

ALTER VIEW [dbo].[v_op_blissue_bs]

as

SELECT     BSNO, 'op_seae' AS OPLB, '海运出口' AS OPLBNAME,'海运出口' AS BSTYPE, CUSTOMERNAME, CUSTNO,ORDERNO,MBLNO, HBLNO,dbo.trimtime(ETD) ETD,dbo.trimtime(ETA) ETA

											,dbo.trimdate(STLDATE) STLDATE, STLNAME, VESSEL, VOYNO, INPUTBY,BLTYPE, 

                                              CREATETIME, BSSTATUS, SALE , OP , DOC, CUSTSERVICE, PORTLOAD, PORTDISCHARGE, '' AS CUSTOMNO, 

                                              ACCDATE,CARRIER, BSSOURCE,BSSOURCEDETAIL, LANE, FORWARDER, 0 AS NETWEIGHT, KGS, TEU, CNTRTOTAL,

                                              CORPID, CNTR1, CNTR2, CNTR3, CNTR4, CNTR5, CNTR6, CNTR7, CNTR8, CNTR9, CNTR10, OTCNTR, '' AS TRADETYPE, GOODSNAME, 

                                              FEESTATUS,ETD AS OPDATE,'' AS CUSTOMDATE,'' ENTERP,PKGS,CBM,BLFRT,SALEDEPT,CUSTOMSNUM,INVNO,'' BSCUSTOMNO,

                                              INSPECTIONDATE,INSPECTIONNO,CONTRACTNO,''BOOKNO,AGENTID,ISPRINTPR,'' as NUMBERPLATE,0 FEEKGS,OPERATOR,SERVICECONTRACTNO,ISCANCEL

                                              ,APPLYNO,ISSUETYPE,BLISSUESTATUS,REMARK,ISGAIQIAN,ISSUEPLACE                                      

                       FROM          dbo.op_seae

                       UNION ALL

                       SELECT   BSNO, 'op_seai' AS OPLB, '海运进口' AS OPLBNAME,'海运进口' AS BSTYPE,CUSTOMERNAME, CUSTNO,ORDERNO,MBLNO, HBLNO,dbo.trimtime(ETD) ETD,dbo.trimtime(ETA) ETA

											,dbo.trimdate(STLDATE) STLDATE,STLNAME STLNAME, VESSEL, VOYNO, INPUTBY,BLTYPE, 

                                             CREATETIME, BSSTATUS, SALE ,OP , DOC, CUSTSERVICE, PORTLOAD, PORTDISCHARGE, ISNULL(CUSTOMNO, '') AS CUSTOMNO,ACCDATE,

                                             CARRIER, BSSOURCE,BSSOURCEDETAIL, LANE, FORWARDER, NETWEIGHT, KGS, TEU, CNTRTOTAL,

                                             CORPID, CNTR1, CNTR2, CNTR3, CNTR4, CNTR5, CNTR6, CNTR7, CNTR8, CNTR9, CNTR10, OTCNTR, TRADETYPE, GOODSNAME, 

                                             FEESTATUS,ETD AS OPDATE,CUSTOMDATE,'' ENTERP,PKGS,CBM,BLFRT,SALEDEPT,CUSTOMSNUM,INVNO,'' BSCUSTOMNO,

                                             INSPECTIONDATE,INSPECTIONNO,CONTRACTNO,'' BOOKNO,AGENTID,ISPRINTPR,NUMBERPLATE,0 FEEKGS,OPERATOR,'' SERVICECONTRACTNO,0 ISCANCEL

                                             ,APPLYNO,ISSUETYPE,BLISSUESTATUS,REMARK,0 ISGAIQIAN,ISSUEPLACE 

                       FROM         dbo.op_seai 

                       UNION ALL

                       SELECT     BSNO, 'op_aire' AS OPLB, '空运出口' AS OPLBNAME,'空运出口' AS BSTYPE, CUSTOMERNAME, CUSTNO,ORDERNO,MBLNO, HBLNO,dbo.trimtime(ETD) ETD,dbo.trimtime(ETA) ETA

											,dbo.trimdate(STLDATE) STLDATE,STLNAME STLNAME, VESSEL,'' VOYNO, INPUTBY,BLTYPE, 

                                              CREATETIME, BSSTATUS, SALE , OP ,'' DOC, CUSTSERVICE, PORTLOAD, PORTDISCHARGE, '' AS CUSTOMNO, 

                                              ACCDATE,AIRLINES CARRIER, BSSOURCE,BSSOURCEDETAIL,'' LANE, FORWARDER, FEEKGS AS NETWEIGHT, KGS,0 TEU,'' CNTRTOTAL,

                                              CORPID,0 CNTR1,0 CNTR2,0 CNTR3,0 CNTR4,0 CNTR5,0 CNTR6,0 CNTR7,0 CNTR8,0 CNTR9,0 CNTR10,0 OTCNTR, '' AS TRADETYPE, GOODSNAME, 

                                              FEESTATUS,ETD AS OPDATE,'' AS CUSTOMDATE,'' ENTERP,PKGS,CBM ,BLFRT,SALEDEPT,CUSTOMSNUM,INVNO,'' BSCUSTOMNO,

                                              INSPECTIONDATE,INSPECTIONNO,CONTRACTNO,'' BOOKNO,AGENTID,ISPRINTPR,'' as NUMBERPLATE,FEEKGS,OPERATOR,'' SERVICECONTRACTNO,0 ISCANCEL

                                              ,'' APPLYNO, ISSUETYPE,BLISSUESTATUS,REMARK,0 ISGAIQIAN,ISSUEPLACE          

                       FROM          dbo.op_aire

                       UNION ALL

                       SELECT     BSNO, 'op_airi' AS OPLB, '空运进口' AS OPLBNAME,'空运进口' AS BSTYPE, CUSTOMERNAME, CUSTNO,ORDERNO,MBLNO, HBLNO,dbo.trimtime(ETA) ETD,dbo.trimtime(ETA) ETA

											,dbo.trimdate(STLDATE) STLDATE,STLNAME STLNAME, VESSEL,'' VOYNO, INPUTBY,BLTYPE, 

                                              CREATETIME, BSSTATUS, SALE ,OP ,'' DOC, CUSTSERVICE, PORTLOAD, PORTDISCHARGE, '' AS CUSTOMNO, 

                                              ACCDATE,AIRLINES CARRIER, BSSOURCE,BSSOURCEDETAIL,'' LANE, FORWARDER, FEEKGS AS NETWEIGHT, KGS,0 TEU,'' CNTRTOTAL,

                                              CORPID,0 CNTR1,0 CNTR2,0 CNTR3,0 CNTR4,0 CNTR5,0 CNTR6,0 CNTR7,0 CNTR8,0 CNTR9,0 CNTR10,0 OTCNTR, '' AS TRADETYPE, GOODSNAME, 

                                              FEESTATUS,ETA AS OPDATE,'' AS CUSTOMDATE,'' ENTERP,PKGS,CBM,BLFRT,SALEDEPT,CUSTOMSNUM,INVNO,'' BSCUSTOMNO,

                                              INSPECTIONDATE,INSPECTIONNO,CONTRACTNO,'' BOOKNO,AGENTID,ISPRINTPR,'' as NUMBERPLATE,FEEKGS,OPERATOR,'' SERVICECONTRACTNO,0 ISCANCEL

                                              ,'' APPLYNO, ISSUETYPE, BLISSUESTATUS,REMARK,0 ISGAIQIAN,'' ISSUEPLACE 

                       FROM          dbo.op_airi



GO


执行:
---
INSERT INTO[t_sys_soft]([版本号],[系统],[版本1],[版本2],[版本3],[软件名称]) VALUES('7.22.0920', NULL, '7', '22', '0920', 'd7')
---
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('0'+ REPLACE(right(@vs_NowDate,2),'-',''),2)
		Set @vs_MonthNo=right('0'+ REPLACE(substring(@vs_NowDate,6,2),'-',''),2)
		select @vs_YearNo,@vs_DayNo,@vs_MonthNo
	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(REPLACE( @vs_TmpBillNo,'-',''),'/',''))
	Set @ps_BillNo= @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(REPLACE( @vs_TmpBillNo,'-',''),'/',''))
	Set @ps_BillNo= @vs_TmpBillNo
    update sys_no set ISUSE=1 where BSNO=@ps_BillNo
  end	   	   
	   
	   
  select @ps_BillNo as BillNo
End


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

ALTER VIEW [dbo].[v_op_gain_sum_shen]
AS
SELECT B.PARENTID BSNO,
      isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,0) ELSE 0 END)
      ELSE 0 END),0) AS RMBDR, 
      isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,0) ELSE 0 END)
      ELSE 0 END),0) AS RMBCR, 
      isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(SETTLEMENT,0) ELSE 0 END)
      ELSE 0 END),0) AS STLRMBDR, 
      isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(SETTLEMENT,0) ELSE 0 END)
      ELSE 0 END),0) AS STLRMBCR,
      isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END) 
      ELSE 0 END),0) AS USDDR, 
      isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END) 
      ELSE 0 END),0) AS USDCR, 
      isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(SETTLEMENT,0) ELSE 0 END) 
      ELSE 0 END),0) AS STLUSDDR, 
      isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(SETTLEMENT,0) ELSE 0 END) 
      ELSE 0 END),0) AS STLUSDCR,      
      isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0  ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT,0) END) END) 
      ELSE 0 END),0) AS OTDR, 
      isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0  ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT,0) END) END) 
      ELSE 0 END),0) AS OTCR, 
      isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0  ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(SETTLEMENT,0) END) END) 
      ELSE 0 END),0) AS STLOTDR, 
      isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0  ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(SETTLEMENT,0) END) END) 
      ELSE 0 END),0) AS STLOTCR,
      cast(round(isnull(SUM(CASE FEETYPE WHEN 1 THEN ISNULL(AMOUNT,0) * ISNULL(EXCHANGERATE,0) ELSE 0 END),0),2) as numeric(20,2)) AS TTLDR,
      cast(round(isnull(SUM(CASE FEETYPE WHEN 2 THEN ISNULL(AMOUNT,0) * ISNULL(EXCHANGERATE,0) ELSE 0 END),0),2) as numeric(20,2)) AS TTLCR,
      cast(round(isnull(SUM(CASE FEETYPE WHEN 1 THEN (ISNULL (SETTLEMENT,0)) * ISNULL(EXCHANGERATE,0) ELSE 0 END),0),2) as numeric(20,2)) AS STLTTLDR,
      cast(round(isnull(SUM(CASE FEETYPE WHEN 2 THEN ISNULL(SETTLEMENT,0) *ISNULL( EXCHANGERATE,0) ELSE 0 END),0),2) as numeric(20,2)) AS STLTTLCR
FROM ch_fee f left join v_op_bill b on b.BSNO=f.BSNO

GROUP BY B.PARENTID
GO

create View V_gain_cust_sum as
select sum(RMBDR-STLRMBDR) RMBDR_ALL,sum(USDDR-STLUSDDR) USDDR_ALL,sum(TTLDR-STLTTLDR) TTLDR_ALL,CUSTOMERNAME from v_op_gain_cust_sum
group by CUSTOMERNAME
GO

alter table op_blissuelist add RMBNODR_ALL numeric(18,2) null
alter table op_blissuelist add USDNODR_ALL numeric(18,2) null
alter table op_blissuelist add TTLNODR_ALL numeric(18,2) null

GO


alter VIEW v_op_gain_blissue_bill
AS
SELECT bl.BSNO BLGID, c.BSNO,bl.CUSTOMERNAME,bl.MBLNO,bl.HBLNO,
      isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,0) ELSE 0 END)
      ELSE 0 END),0) AS RMBDR, 
      isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,0) ELSE 0 END)
      ELSE 0 END),0) AS RMBCR, 
      isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(SETTLEMENT,0) ELSE 0 END)
      ELSE 0 END),0) AS STLRMBDR, 
      isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(SETTLEMENT,0) ELSE 0 END)
      ELSE 0 END),0) AS STLRMBCR,
      isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END) 
      ELSE 0 END),0) AS USDDR, 
      isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END) 
      ELSE 0 END),0) AS USDCR, 
      isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(SETTLEMENT,0) ELSE 0 END) 
      ELSE 0 END),0) AS STLUSDDR, 
      isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(SETTLEMENT,0) ELSE 0 END) 
      ELSE 0 END),0) AS STLUSDCR,      
      isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0  ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT,0) END) END) 
      ELSE 0 END),0) AS OTDR, 
      isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0  ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT,0) END) END) 
      ELSE 0 END),0) AS OTCR, 
      isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0  ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(SETTLEMENT,0) END) END) 
      ELSE 0 END),0) AS STLOTDR, 
      isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0  ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(SETTLEMENT,0) END) END) 
      ELSE 0 END),0) AS STLOTCR,
      cast(round(isnull(SUM(CASE FEETYPE WHEN 1 THEN ISNULL(AMOUNT,0) * ISNULL(EXCHANGERATE,0) ELSE 0 END),0),2) as numeric(20,2)) AS TTLDR,
      cast(round(isnull(SUM(CASE FEETYPE WHEN 2 THEN ISNULL(AMOUNT,0) * ISNULL(EXCHANGERATE,0) ELSE 0 END),0),2) as numeric(20,2)) AS TTLCR,
      cast(round(isnull(SUM(CASE FEETYPE WHEN 1 THEN ISNULL(SETTLEMENT,0) * ISNULL(EXCHANGERATE,0) ELSE 0 END),0),2) as numeric(20,2)) AS STLTTLDR,
      cast(round(isnull(SUM(CASE FEETYPE WHEN 2 THEN ISNULL(SETTLEMENT,0) *ISNULL( EXCHANGERATE,0) ELSE 0 END),0),2) as numeric(20,2)) AS STLTTLCR
FROM  v_op_blissue_bill bl 
left join ch_fee c on bl.PARENTID=c.BSNO and c.CUSTOMERNAME=bl.CUSTOMERNAME

GROUP BY c.BSNO,BL.CUSTOMERNAME,bl.bsno,bl.MBLNO,bl.HBLNO
GO


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


alter VIEW v_op_gain_blissue_bill
AS
SELECT bl.BSNO BLGID, c.BSNO,bl.CUSTOMERNAME,bl.MBLNO,bl.HBLNO,
      isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,0) ELSE 0 END)
      ELSE 0 END),0) AS RMBDR, 
      isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,0) ELSE 0 END)
      ELSE 0 END),0) AS RMBCR, 
      isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(SETTLEMENT,0) ELSE 0 END)
      ELSE 0 END),0) AS STLRMBDR, 
      isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(SETTLEMENT,0) ELSE 0 END)
      ELSE 0 END),0) AS STLRMBCR,
      isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END) 
      ELSE 0 END),0) AS USDDR, 
      isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END) 
      ELSE 0 END),0) AS USDCR, 
      isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(SETTLEMENT,0) ELSE 0 END) 
      ELSE 0 END),0) AS STLUSDDR, 
      isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(SETTLEMENT,0) ELSE 0 END) 
      ELSE 0 END),0) AS STLUSDCR,      
      isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0  ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT,0) END) END) 
      ELSE 0 END),0) AS OTDR, 
      isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0  ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT,0) END) END) 
      ELSE 0 END),0) AS OTCR, 
      isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0  ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(SETTLEMENT,0) END) END) 
      ELSE 0 END),0) AS STLOTDR, 
      isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0  ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(SETTLEMENT,0) END) END) 
      ELSE 0 END),0) AS STLOTCR,
      cast(round(isnull(SUM(CASE FEETYPE WHEN 1 THEN ISNULL(AMOUNT,0) * ISNULL(EXCHANGERATE,0) ELSE 0 END),0),2) as numeric(20,2)) AS TTLDR,
      cast(round(isnull(SUM(CASE FEETYPE WHEN 2 THEN ISNULL(AMOUNT,0) * ISNULL(EXCHANGERATE,0) ELSE 0 END),0),2) as numeric(20,2)) AS TTLCR,
      cast(round(isnull(SUM(CASE FEETYPE WHEN 1 THEN ISNULL(SETTLEMENT,0) * ISNULL(EXCHANGERATE,0) ELSE 0 END),0),2) as numeric(20,2)) AS STLTTLDR,
      cast(round(isnull(SUM(CASE FEETYPE WHEN 2 THEN ISNULL(SETTLEMENT,0) *ISNULL( EXCHANGERATE,0) ELSE 0 END),0),2) as numeric(20,2)) AS STLTTLCR
FROM  v_op_blissue_bill bl 
left join ch_fee c on bl.PARENTID=c.BSNO and c.CUSTOMERNAME=bl.CUSTOMERNAME

GROUP BY c.BSNO,BL.CUSTOMERNAME,bl.bsno,bl.MBLNO,bl.HBLNO
GO


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








ALTER VIEW [dbo].[v_op_bill]
AS
select *,isnull(t.CUSTNO,'')+','+isnull(t.MBLNO,'')+','+isnull(t.HBLNO,'')+','+isnull(t.CUSTOMNO,'')+','+isnull(t.ORDERNO,'') ALLBILLNO from(

SELECT     MASTERNO,BSNO,BSNO PARENTID, '普通货' OPTYPE,OPLB, OPLBNAME, BSTYPE,CUSTOMERNAME, CUSTNO,ORDERNO,MBLNO, HBLNO, case ETD when '1900-01-01 00:00:00.000' then '' else CONVERT(varchar, ETD,23) end as ETD
                      ,ETA,STLDATE,STLNAME,VESSEL, VOYNO, INPUTBY, CREATETIME, BSSTATUS, SALE, OP, DOC, 
                      CUSTSERVICE, PORTLOAD, PORTDISCHARGE, CUSTOMNO, ACCDATE,CARRIER, BSSOURCE,BSSOURCEDETAIL, LANE, FORWARDER, NETWEIGHT, KGS, TEU, CNTRTOTAL,
                                              SALECORPID as CORPID, CNTR1, CNTR2, CNTR3, CNTR4, CNTR5, CNTR6, CNTR7, CNTR8, CNTR9, CNTR10, OTCNTR,TRADETYPE, GOODSNAME, 
                                              FEESTATUS,OPDATE,CUSTOMDATE,ENTERP,PKGS,CBM,BLFRT,SALEDEPT,CUSTOMSNUM,INVNO,BSCUSTOMNO,INSPECTIONDATE,INSPECTIONNO
                                              ,CONTRACTNO,BOOKNO,AGENTID,ISPRINTPR,NUMBERPLATE,FEEKGS,OPERATOR,SERVICECONTRACTNO,BLTYPE,ISCANCEL,APPLYNO,ISSUETYPE,BLISSUESTATUS,REMARK,TRADETERM,'' REASON,PLACERECEIPT,DESTINATION,CNTRSEALNO,BillFeeStatus,ISVOU,VOUNO,SALECORPID,YARD,DELIVERYDATE,FRCUSTSERVICE,SERVICE,REMARK2,BILLFEESTATUSTIME,TRUCKER,CUSTOMSER,CLOSINGDATE,KINDPKGS,CARGOID,DCLASS,ATD      
FROM         v_op_bs
UNION ALL
SELECT     B.MASTERNO,A.BSNO,A.PARENTID,'更改单' OPTYPE,B.OPLB, B.OPLBNAME, B.BSTYPE,B.CUSTOMERNAME,CASE WHEN A.AMENDNO IS NULL OR A.AMENDNO='' THEN B.CUSTNO ELSE A.AMENDNO END CUSTNO,B.ORDERNO,B.MBLNO, B.HBLNO, case B.ETD when '1900-01-01 00:00:00.000' then '' else CONVERT(varchar, B.ETD,23) end as ETD
                      ,B.ETA,B.STLDATE,B.STLNAME,B.VESSEL, B.VOYNO, A.CREATEUSER, A.CREATETIME, B.BSSTATUS, A.SALE, B.OP, B.DOC, 
                      B.CUSTSERVICE, B.PORTLOAD, B.PORTDISCHARGE, B.CUSTOMNO, A.ACCDATE,B.CARRIER, B.BSSOURCE,B.BSSOURCEDETAIL, B.LANE, B.FORWARDER,B.NETWEIGHT, B.KGS, 0 TEU, B.CNTRTOTAL,
                                              B.SALECORPID as CORPID, 0 CNTR1, 0 CNTR2, 0 CNTR3, 0 CNTR4, 0 CNTR5, 0 CNTR6, 0 CNTR7, 0 CNTR8, 0 CNTR9, 0 CNTR10, 0 OTCNTR,B.TRADETYPE, B.GOODSNAME, 
                                              A.FEESTATUS,B.OPDATE,B.CUSTOMDATE,B.ENTERP,B.PKGS,B.CBM,B.BLFRT,B.SALEDEPT,B.CUSTOMSNUM,B.INVNO,B.BSCUSTOMNO,B.INSPECTIONDATE
                                              ,B.INSPECTIONNO,B.CONTRACTNO,B.BOOKNO,B.AGENTID,B.ISPRINTPR,B.NUMBERPLATE,B.FEEKGS,B.OPERATOR,B.SERVICECONTRACTNO,B.BLTYPE,B.ISCANCEL,B.APPLYNO,B.ISSUETYPE,B.BLISSUESTATUS,B.REMARK,B.TRADETERM,A.REASON,PLACERECEIPT,DESTINATION,CNTRSEALNO,A.BillFeeStatus,A.ISVOU,A.VOUNO,B.SALECORPID,B.YARD,B.DELIVERYDATE,B.FRCUSTSERVICE,B.SERVICE,B.REMARK2,A.BILLFEESTATUSTIME,B.TRUCKER,B.CUSTOMSER,B.CLOSINGDATE,B.KINDPKGS,B.CARGOID,B.DCLASS,B.ATD                
FROM  op_amend A WITH (NOLOCK) left join v_op_bs B on (B.BSNO=A.PARENTID)
)t

GO


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




INSERT INTO [dbo].[action] ([GID], [NAME], [DESCRIPTION], [MODULEID], [CREATEUSER], [CREATETIME], [MODIFIEDUSER], [MODIFIEDTIME], [STATE], [SORT]) VALUES ('B2286FA5-D701-4894-BAC0-57A3E3C7615C', 'SysRoleTaskQueryModule', '工作台角色待办项目', 'B2286FA5-D701-4894-BAC0-57A3E3C7615C', '1BEC90E1-9780-472F-90C2-0C6390C044A4', '2022-10-31 16:04:58.720', NULL, '2022-10-31 16:04:58.720', 0, 0)
GO

INSERT INTO [dbo].[sys_module] ([GID], [NAME], [DESCRIPTION], [MODULEURL], [MODULEICON], [STATE], [SORT], [PARENTID], [CREATEUSER], [CREATETIME], [MODIFIEDUSER], [MODIFIEDTIME], [SHOWROOTSTATE], [TYPE], [ename], [MODTYPE]) VALUES ('B2286FA5-D701-4894-BAC0-57A3E3C7615C', 'SysRoleTaskQueryModule', '工作台角色待办项目', 'SysMng/SysRoleTaskQuery', 'Module.gif', 0, 23, '2fb6734-7bf6-4a90-8258-510e8b3e2a13', '1BEC90E1-9780-472F-90C2-0C6390C044A4', '2022-10-31 16:04:58.710', NULL, NULL, 0, 0, NULL, NULL)
GO




CREATE TABLE [dbo].[Sys_Role_Task_Query](
	[GID] [uniqueidentifier] NOT NULL,
	[COMPANYID] [varchar](36) NULL,
	[RoleId] [uniqueidentifier] NULL,
	[RoleName] [varchar](200) NULL,
	[FormName] [varchar](200) NULL,
	[MODNAME] [varchar](200) NULL,
	[BSTYPE] [varchar](200) NULL,
	[URL] [varchar](500) NULL,
	[FIELDVALUES] [varchar](max) NULL,
	[SQLCONTEXT] [varchar](max) NULL,
	[SQLSTR] [varchar](2000) NULL,
	[REMARK] [varchar](2000) NULL,
	[ISSTOP] [bit] NOT NULL  DEFAULT ((0)),
 CONSTRAINT [PK_Sys_Role_Task_Head] PRIMARY KEY CLUSTERED 
(
	[GID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO




ALTER view [dbo].[VW_sys_roleauth] as select * from sys_roleauth where name is not null
GO


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


create VIEW [dbo].[VW_user_all]
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


GO


