【发布时间】:2021-06-16 17:04:33
【问题描述】:
我正在使用 Query 将一些数据带入 Excel,但是行数过多,文件超过 70 MB,崩溃了几次。 我需要按月恢复的值,其中有人在 Excel 单元格中填写月份,Excel 查询会使用该值更新。
我尝试做某事,但没有得到我预期的结果 我在下面尝试的查询:
DECLARE @Month Varchar(2);
SET @Month = ?
select distinct C.Code as ResourceCode, C.Name as ResourceName, sum( case when B.Code = '069' then MovQty * -1 else MovQty end) QTY,
B.Code as MovCode, B.Name as MovType from TBLMovEv A
inner join TBLMovType B on A.IDMovType = B.IDMovType
inner join TBLResource C on C.IDResource = a.IDResource
inner join TBLProduct D on D.IDProduct = A.IDProduct where
year(DtMov) = 2021
and Month(DtMov) = @Month
and day(DtMov) < (case when Month(getdate()) <> @Month then day(getdate()) else 32 end)
and B.Code in ('068', '069')
and C.Code NOT like '[CKLOM]%'
and C.Code not like '[ABQ][E][M]%'
and MovQty <> 0
GROUP BY B.CODE, B.NAME, C.CODE, C.NAME, DtMov
ORDER BY C.Code
我的问题是,当参数化的月份与 getdate 月份不同时,我希望那一天可能是
我想知道是否有一种方法可以将@Month 变量设置为参数,或者一种解决方法。
我还尝试获取仅包含 de month 的列,然后通过 excel 公式进行过滤,但它仍然得到接近 10.000 行的内容,这是我想避免的。 我可以直接从 SQL 获得的数据量越少越好。
【问题讨论】:
标签: sql-server excel export-to-excel