解释起来有点困难,但基本上我需要创建一个临时表(日期日期时间,#customers int),其中 #customers 是从另一个表中提取的每周客户数。这是我的代码。
declare @date datetime
declare @temptable table (date datetime not null,#customers int)
set @date='2018-02-13'
while @date<getdate()
begin
insert into @temptable values
(@date,
(select count(*) from in_ft_conversion
where u4='cfa' and sales_date between @date and @date-7))
set @date=@date+7
end
结果是一个包含所有正确日期条目但客户列中为 0 的表......有人知道我做错了什么吗?谢谢!
您的日期范围错误,请交换 BETWEEN 中的日期值,以便您拥有 BETWEEN <earlier date> AND <later date>
where u4='cfa' and sales_date between @date-7 and @date))
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句