我想将@batch 日期传入batch_date ...但它显示错误...错误是
列 'dbo.tnx_tid_InvCheck_Details.Batch_Date' 在选择列表中无效,因为它不包含在聚合函数或 GROUP BY 子句中。
该InvCheck_Details
表有batch_date
每一个part_no
。我想对 part_no 进行分组,以便我可以按 part_no 计数(tid)和 sum(tid_bal)。我应该怎么做才能运行这个脚本?天...
DECLARE @batch_date datetime
SET @batch_date = '2012-10-13 00:00:00.000'
CREATE TABLE #inv_check
(batch_date datetime,part_no varchar(25),Number_of_tid int,Updated_DT int, Tot_Tid_Bal int)
INSERT INTO #inv_check
SELECT batch_date,part_no,COUNT(tid)as Number_of_tid,0,sum(Tid_Bal)
FROM dbo.tnx_tid_InvCheck_Details
where batch_date = @batch_date
Group by part_no
order by part_no
UPDATE #inv_check
SET Updated_DT = isnull(d.Updated_DT,0)
--select i.part_no,i.Number_of_tid, isnull(d.Updated_DT,0)
FROM #inv_check i
LEFT OUTER JOIN
(SELECT part_no, COUNT(LastUpdate_DT)as Updated_DT,
sum(tid_bal) as Tid_bal_sum
FROM dbo.tnx_tid_InvCheck_Details
Where NOT LastUpdate_DT IS NULL
Group by part_no) d on i.part_no=d.part_no
DECLARE @sql int
DECLARE @sql1 int
SELECT @sql1 = count(part_no)
FROM #inv_check
SELECT @sql = count(part_no)
FROM #inv_check
WHERE number_of_tid= Updated_DT
SELECT @sql AS Parts_Counted,@sql1 AS Full_Parts
Drop table #inv_check