不确定我是否可以加入从交叉应用函数中获得的结果:
select
iv.invoiceno
,w.warehouse
,iv.invoicedate
,iv.invoicedesc
,iv.status
,iv.billingstart as [BillingFrom]
,iv.billingend as [BillingTo]
,CAST((iv.invoicesubtotal) as NUMERIC(38,2))as [Sub-Total]
,CAST((((iv.invoicesubtotal+iv.invoicetax)-iv.invoicetotal)) as NUMERIC(38,2)) as [Discount]
,CAST((iv.invoicetax) as NUMERIC(38,2)) as [SalesTax]
,CAST((iv.invoicetotal) as NUMERIC(38,2)) as [Total]
,d.deal
,d.dealno
,ivt.orderno
,ivt.rectype
,ivt.rectypedisplay
,RTRIM(ivt.masterno) as [ICode]
,ivt.description as [ICodeDesc]
,ivt.fromdate as [From]
,ivt.todate as [To]
,CAST((ivt.days ) as NUMERIC(38,2)) as [days]
,CAST(ivt.qty as NUMERIC(38,0)) as [qty]
,CAST((ivt.cost) as NUMERIC(38,2)) as [UnitCost]
,CAST((ivt.rate) as NUMERIC(38,2)) as [rate]
,CAST((ivt.daysinwk)as NUMERIC(38,2)) as [D/W]
,CAST((ivt.discountamt)as NUMERIC(38,2)) as [Discount]
,CAST((ivt.extended)as NUMERIC(38,2)) …Run Code Online (Sandbox Code Playgroud) 我已声明一个包含以下变量的表:
CREATE TABLE #tmp
(
[Counter] int
,Period Date primary key
,VanMe float
)
Run Code Online (Sandbox Code Playgroud)
我已经做了一些设置VanMe的步骤.
以下是发生错误的With和Select语句:
我把它缩小到了With的第一部分因为Report Builder cte.Period和#tmp.Period被认为是相同的两个键.在我更改了它并使用了Select语句后,它仍然给了我同样的错误.
有没有办法可以在With语句中计算平均值而只是调用
Select * from #tmp.
Run Code Online (Sandbox Code Playgroud)
我尝试了更新它根本不起作用.它给了我VanMeAvg和其他Avg变量的null.
请帮忙!
我得到的错误是这样的:
An item with the same key has already been added.
Run Code Online (Sandbox Code Playgroud)