同一个数据库下面的两个完全相同的数据实例,一个是2016年的,一个是2017年的。
不管数据怎样,一个报错一个不报错,找原因都没有方向!
各个表结构方面都是一样的,但脚本的语法是否错误应该和数据内容无关吧?
语句如下:
SELECT Distinct convert(nvarchar(10),IA_Subsidiary.dKeepDate,21) as dKeepDate,
convert(nvarchar(10),IA_Subsidiary.dVouDate,21) as dVouDate,enum1.enumname AS cVouchName,IA_Subsidiary.cVouCode,
case when cvoutype= N'22' then N'' else (case when (0=1 and cvoutype= N'35') then N'' else cWhName end) end as cWhName,
case when cvoutype= N'35' then N'' else Rd_Style.cRdName end as cRdName,IA_Subsidiary.cAccounter, IA_Subsidiary.cVouType,
case when cvoutype= N'22' then N'' else (case when (0=1 and cvoutype= N'35') then N'' else IA_Subsidiary.cWhCode end) end as cWhcode,
case when cvoutype= N'35' then N'' else Rd_Style.cRdCode end as cRdCode,case when cvoutype= N'35' then N'' else cDepName end as cAccDepName,
case when cvoutype= N'35' then N'' else cAccDep end as cAccDepCode,case when cvoutype= N'22' then N'' else IA_Subsidiary.cDepCode end as cDepCode,
case when (left(IsNull(IA_Subsidiary.cBusType, N''),2)= N'调拨' or left(IsNull(IA_Subsidiary.cBusType, N''),2)= N'组装' or left(IsNull(IA_Subsidiary.cBusType, N''),2)= N'拆卸' or left(IsNull(IA_Subsidiary.cBusType, N''),2)= N'转换') then IA_Subsidiary.cBusCode else N'' end As cBusCode,
CASE WHEN (cVouType= N'24' or cVouType= N'30') then IA_Subsidiary.AutoID else ipzid end as MainID,
IA_Subsidiary.id as id,
enum2.enumname as cBusTypeDis,IA_Subsidiary.cSrcVouType,enum3.enumname as cWhValueStyleDis, 'Sub' As cSource, IA_Subsidiary.AutoID, IA_Subsidiary.ID, IsNull(IA_Subsidiary.cBusType, N'') As cBusType,IA_Subsidiary.psvsid as psvsid
FROM (Warehouse RIGHT JOIN (department RIGHT JOIN (Rd_Style RIGHT JOIN (VouchType RIGHT JOIN IA_Subsidiary ON VouchType.cVouchType = IA_Subsidiary.cVouType)
ON Rd_Style.cRdCode = IA_Subsidiary.cRdCode) ON department.cDepCode = IA_Subsidiary.cAccDep) ON Warehouse.cWhCode = IA_Subsidiary.cWhCode)
Left join inventory on ia_subsidiary.cinvcode=inventory.cinvcode
left join aa_enum enum1 on enum1.enumtype= N'IA.VchType' and enum1.enumcode=(case when CVOUTYPE= N'2501' then N'直运采购发票'else
(CASE WHEN CVOUTYPE= N'35' THEN N'差异结转单' ELSE case when (IsNull(IA_Subsidiary.cBusType, N'')= N'假退料' and cvoutype= N'11') then N'假退料单' else
VouchType.cVouchName end END) end ) and enum1.localeid= dbo.UDF_GetLocaleID()
left join aa_enum enum2 on enum2.enumtype= N'IA.Bustype' and enum2.enumcode=IsNull(IA_Subsidiary.cBusType, N'') and enum2.localeid= dbo.UDF_GetLocaleID()
left join aa_enum enum3 on enum3.enumtype= N'IA.ValueStyle' and enum3.enumcode=(case when cvoutype= N'22' then N'' else
(case when (0=1 and cvoutype= N'35') then N'' else cWhValueStyle end) end ) and enum3.localeid= dbo.UDF_GetLocaleID()
left join Rdrecords RdsCheck on RdsCheck.bCosting = 1 And RdsCheck.ID = IA_Subsidiary.iPZID And IsNull(RdsCheck.cBAccounter, N'') = N'' and Not Left(IA_Subsidiary.cVouType, 2) In (N'70', N'ex', N'05', N'06', N'5', N'6', N'25', N'26', N'27', N'28', N'29', N'20', N'21', N'22', N'35', N'24', N'30')
left join PU_T_VMIUsedVouchs VmiCheck on VmiCheck.bCosting = 1 And VmiCheck.ID = IA_Subsidiary.iPZID And IsNull(VmiCheck.cBAccounter, N'') = N'' and Left(IA_Subsidiary.cVouType, 2) In (N'70')
left join DispatchLists DisCheck on DisCheck.bCosting = 1 And DisCheck.DLID = IA_Subsidiary.iPZID And IsNull(DisCheck.cBAccounter, N'') = N'' and Left(IA_Subsidiary.cVouType, 2) In (N'05', N'06', N'5', N'6')
left join SalebillVouchs BillCheck on BillCheck.bCosting = 1 And BillCheck.SBVID = IA_Subsidiary.iPZID And IsNull(BillCheck.cBAccounter, N'') = N'' and Left(IA_Subsidiary.cVouType, 2) In (N'26', N'27', N'28', N'29')
left join purbillvouchs pusCheck on pusCheck.bCosting = 1 And pusCheck.PBVID = IA_Subsidiary.iPZID And IsNull(pusCheck.cBAccounter, N'') = N'' and Left(IA_Subsidiary.cVouType, 2) = N'25'
left join JustInVouchs JustCheck on JustCheck.bCosting = 1 And JustCheck.cJVCode = IA_Subsidiary.cVouCode And IsNull(JustCheck.cBAccounter, N'') = N'' and IA_Subsidiary.cVouType In (N'20', N'21')
left join ex_invoicedetail EXsCheck on EXsCheck.bCosting = 1 And EXsCheck.ID = IA_Subsidiary.iPZID And IsNull(EXsCheck.cBAccounter, N'') = N'' and Left(IA_Subsidiary.cVouType, 2) = N'ex'
where IA_subsidiary.cVouType<> N'33' and IA_subsidiary.cVouType<> N'34' and ((imonth<>0 and substring(IsNull(IA_Subsidiary.cBusType, N''),1,2) = N'直运') or substring(IsNull(IA_Subsidiary.cBusType, N''),1,2) <> N'直运' or IA_subsidiary.cbustype is null) and cpzid is null
And RdsCheck.ID Is Null And VmiCheck.ID Is Null And DisCheck.DLID Is Null And BillCheck.SBVID Is Null And pusCheck.ID Is Null And JustCheck.cJVCode Is Null And EXsCheck.ID Is Null
AND IA_Subsidiary.cVouCode>= N'123456' AND ((Ia_Subsidiary.cVouType= N'01' and bFlag=1) or (Ia_Subsidiary.cVouType= N'01' and bFlag<>1) or (Ia_Subsidiary.cVouType= N'70' and bFlag=1) or (Ia_Subsidiary.cVouType= N'70' and bFlag<>1) or (Ia_Subsidiary.cVouType= N'10') or (Ia_Subsidiary.cVouType= N'08') or (Ia_Subsidiary.cVouType= N'26' and Ia_Subsidiary.cBusType <> N'直运销售' ) or (Ia_Subsidiary.cVouType= N'27' and Ia_Subsidiary.cBusType <> N'直运销售' ) or (Ia_Subsidiary.cVouType= N'28' and Ia_Subsidiary.cBusType <> N'直运销售' ) or (Ia_Subsidiary.cVouType= N'29' and Ia_Subsidiary.cBusType <> N'直运销售' ) or (Ia_Subsidiary.cVouType= N'32' and Ia_Subsidiary.cBusType <> N'直运销售' ) or (Ia_Subsidiary.cVouType= N'11' and Ia_Subsidiary.cBusType<> N'假退料' ) or (Ia_Subsidiary.cVouType= N'09' and Ia_Subsidiary.cBusType <> N'直运销售' ) or (Ia_Subsidiary.cVouType= N'20' and (isnull(iAInPrice,0)<>0 or isnull(iDebitDifCost,0)<>0 or isnull(iCreditDifCost,0)<>0)) or (Ia_Subsidiary.cVouType= N'21') or (Ia_Subsidiary.cVouType= N'22') or (Ia_Subsidiary.cVouType= N'35') or (Ia_Subsidiary.cVouType= N'24') or (Ia_Subsidiary.cVouType= N'30' and bFlag=1) or (Ia_Subsidiary.cVouType= N'30' and bFlag<>1) or (Ia_Subsidiary.cVouType= N'05' and Ia_Subsidiary.cBusType= N'分期收款' and imonth <> 0) or (Ia_Subsidiary.cVouType= N'05') or (Ia_Subsidiary.cVouType= N'06') or (Ia_Subsidiary.cVouType= N'AA') or (Ia_Subsidiary.cVouType= N'AA') or (Ia_Subsidiary.cVouType= N'27' and not iOutCost is null and imonth <> 0 and not Ia_Subsidiary.cBusType in (N'分期收款',N'委托',N'直运销售') ) or (Ia_Subsidiary.cVouType= N'27' and not iOutCost is null and imonth <> 0 and not Ia_Subsidiary.cBusType in (N'分期收款',N'委托',N'直运销售') ) or (Ia_Subsidiary.cVouType= N'66') or (Ia_Subsidiary.cVouType= N'66') or (Ia_Subsidiary.cVouType Like N'25%' and Ia_Subsidiary.cBusType= N'直运采购' and imonth <> 0) or (Ia_Subsidiary.cVouType= N'25') or (Ia_Subsidiary.cVouType in ( N'26',N'27') and Ia_Subsidiary.cBusType= N'直运销售' and imonth <> 0 ) or (Ia_Subsidiary.cVouType In ( N'EX26',N'EX27') and Ia_Subsidiary.cBusType <> N'直运销售' ) or (Ia_Subsidiary.cVouType in ( N'EX26',N'EX27') and Ia_Subsidiary.cBusType= N'直运销售' and imonth <> 0 ) or (Ia_Subsidiary.cVouType= N'11' and Ia_Subsidiary.cBusType= N'假退料' ) or (Ia_Subsidiary.cVouType= N'61')) and ( ((Not warehouse.cwhcode IN (Select cWhCode From Warehouse Where bInCost = 0)) or warehouse.cwhcode is null) Or warehouse.cwhcode Is Null)
Order by IA_Subsidiary.cVouType,IA_Subsidiary.dKeepDate,IA_subsidiary.cVoucode,IA_Subsidiary.cWhCode