|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册账号
×
是哪个字段,改哪个表?求高人指点
错误信息:
-2147217900
列名 'cInvM_Unit' 无效。
执行如下语句时出错:
CREATE PROCEDURE Sa_MoveSaleProfit( /* 取得销售毛利分析数据存储过程 */
@chrtable varchar(200) = null , /*保存销售毛利分析明细账*/
@chrWhere1 varchar(255) =null , /* 查询条件名称,不包括日期条件 */
@chrStartDate varchar (200)=null, /* 分析上期日期区间*/
@chrEndDate varchar (200)=null, /* 分析本期日期区间*/
@chrDate varchar (200)=null ,/* 总的日期区间 */
@chrBZ varchar(30) /* 币种条件 */
)
AS
declare @chrSQL varchar(4000)
declare @chrCost varchar(50)
declare @chrWhere varchar(1000)
declare @chrCostWhere varchar(300)
declare @chrstartdate1 varchar (50)
/* 取得除去日期的条件 */
if ltrim(rtrim(@chrwhere1 )) = 'newReport_ParameterFromTempTable'
begin
/*条件参数通过临时表传递 */
set @chrCostWhere = (select name from tempdb..newReportParameter )
end
else /*条件参数直接传递 */
begin
set @chrCostWhere = rtrim(ltrim(@chrwhere1))
end
/*构造收入条件和成本条件 */
set @chrwhere = @chrCostWhere
if not (@chrbz is null ) and ltrim(rtrim(@chrbz)) <> ''
if not(@chrwhere is null ) and ltrim(rtrim(@chrWhere)) <> ''
set @chrwhere = @chrwhere + ' and ' + @chrBZ
/* 取销售系统启用日期 */
set @chrStartDate1 = (select isnull(cValue,'1900-01-01') from accinformation where cSysid='Sa' and cName='dStartDate' )
if @chrstartdate1 <> ''
begin
if len(ltrim(rtrim(@chrstartdate1))) <= 8 set @chrstartdate1 = convert(varchar(10),convert(smalldatetime,@chrstartdate1,2),121)
set @chrstartDate1 = ' and SalebillVouch.dDate>=''' + @chrstartdate1 + ''''
end
/* 查询成本明细账,计算出成本,毛利,成本单价,销售单价,数量,金额 */
if exists(select * from tempdb..sysobjects where name='Pr_SaleIncomefirst') drop table tempdb..Pr_SaleIncomefirst
/* 查询收入的,金额售价,售价 */
set @chrSQL ='
SELECT
SaleBillVouchs.AutoID AS AutoID,
SaleBillVouchs.iQuantity AS iQuantity,
SaleBillVouchs.iNatUnitPrice AS iNatUnitPrice,
SaleBillVouchs.iNatMoney as iNatMoney ,
SaleBillVouch.cExch_name as cExch_name,
SaleBillVouch.dDate as dDate,
SaleType.cSTName as cSTName ,
Customer.cCusName as cCusName ,
CustomerClass.cCCName as cCCname ,
Inventory.cInvName as cInvName ,
Inventory.cInvStd as cInvStd ,
Inventory.cInvM_Unit as cInvM_Unit,
Inventory.cInvCCode as cInvCCode,
Department.cDepName as cDepName ,
Department.cDepCode as cDepCode ,
SaleBillVouch.cSTCode as cSTCode,
SaleBillVouch.cCusCode as cCusCode,
SaleBillVouchs.cInvCode as cInvCode,
Customer.cCCCode as cCCCode ,
Inventory.bService as bService
INTO tempdb..Pr_SaleInComefirst
FROM SaleBillVouchs INNER JOIN SaleBillVouch On SalebillVouchs.sbvid = SalebillVouch.sbvid
LEFT JOIN Customer On SalebillVouch.cCusCode = Customer.cCusCode
LEFT JOIN CustomerClass On Customer.cCCCode = CustomerClass.cCCCode
LEFT JOIN SaleType On SaleBillVouch.cSTCode = SaleType.cSTCode
LEFT JOIN Inventory On SaleBillVouchs.cInvCode = Inventory.cInvCode
LEFT JOIN Department On SaleBillVouch.cDepCode = Department.cDepCode
WHERE isnull(Salebillvouch.cInvalider,'''')=''''
and isnull(Salebillvouch.cSTCode,'''') <> ''''
' + @chrstartdate1 /*作废发票不能计算在内,销售类型不能为空,开票日期必须大于系统起用日期 */
/* 执行存储过程,取得本期销售内容 */
if not (@chrDate is null ) and ltrim(rtrim(@chrdate)) <>'' set @chrSQL = @chrSQL + ' And ' + @chrDate
exec (@chrsql )
/* 按普通条件抽取数据 */
if exists(select * from tempdb..sysobjects where name='Pr_SaleIncome') drop table tempdb..Pr_SaleIncome
set @chrsql = 'Select * into tempdb..Pr_saleIncome from tempdb..Pr_saleincomefirst '
if not ( @chrwhere is null) and @chrwhere<>'' set @chrSQL = @chrSQL +' WHERE ' + @chrWhere
exec (@chrsql )
/* 计算成本明细,按发票ID号取得成本明细 */
/*数据准备*/
if exists(select * from tempdb..sysobjects where name='Pr_SaleCostFirst') drop table tempdb..Pr_SaleCostFirst SELECT IA_Subsidiary.dKeepDate AS ddate,
IA_Subsidiary.cVouType AS cvoutype,
IA_Subsidiary.iOutCost AS iOutCost,
case when (cWhvaluestyle='计划价法'or cWhvalueStyle='售价法') and IA_Subsidiary.bMoneyFlag=1 then
isnull(IA_Subsidiary.iAOutPrice,0)- isnull( IA_Subsidiary.iDebitDifCost,0) + isnull( IA_Subsidiary.iCreditDifCost,0)
else
isnull(IA_Subsidiary.iAOutPrice ,0)
end
as iAOutPrice,
IA_SubSidiary.cSTCode as cSTCode,
Customer.cCCCode as cCCCode ,
Inventory.cInvCode as cInvCode ,
Inventory.cInvCCode as cInvCCode ,
IA_Subsidiary.cCusCode AS cCusCode,
IA_Subsidiary.cAccDep AS cDepCode,
IA_Subsidiary.cDepCode AS cAccDep ,
IA_Subsidiary.iMonth AS iMonth,
IA_Subsidiary.bMoneyFlag AS bMoneyFlag,
IA_Subsidiary.bSale AS bSale,
IA_Subsidiary.cWhCode as cWhCode ,
Warehouse.cWhValueStyle AS cWhValueStyle ,
IA_Subsidiary.cBillCode AS cBillCode,
IA_Subsidiary.cDLCode AS cDlCode ,
IA_Subsidiary.iAOutQuantity as iAOutQuantity ,
SaleType.cSTName as cSTName ,
Customer.cCusName as cCusName ,
CustomerClass.cCCName as cCCname ,
Inventory.cInvName as cInvName ,
Inventory.cInvStd as cInvStd ,
Inventory.cInvM_Unit as cInvM_Unit,
Department.cDepName as cDepName ,
Inventory.bService as bService
INTO tempdb..Pr_SaleCostfirst
FROM IA_Subsidiary LEFT JOIN Warehouse ON IA_Subsidiary.cWhCode = Warehouse.cWhCode
LEFT JOIN Customer On IA_Subsidiary.cCusCode = Customer.cCusCode
LEFT JOIN Inventory On IA_SubSidiary.cInvCode = Inventory.cInvCode
LEFT JOIN Department On IA_SubSidiary.cAccDep = Department.cDepCode
LEFT JOIN CustomerClass On Customer.cCCCode = CustomerClass.cCCCode
LEFT JOIN SaleType On IA_SubSidiary.cSTCode = SaleType.cSTCode
WHERE bRdFlag=0 AND (cVouType in ('26','27','28','29','32') or (cVoutype='21' and Ia_subsidiary.bSale=1 ) )
|
|