select
sum(A.[usercount1]) as [2015-01]
,Sum(A.[usercount2]) as [2015-02]
from
(select
startdate
enddate
when '2015-01-31' > U.startdate and '2015-01-31' < U.enddate then count(username)
Else NULL
End as 'usercount1'
,
Case
when '2015-02-31' > U.startdate and '2015-02-31' < U.enddate then count(username)
Else NULL
End as 'usercount2'
FROM U
group by U.enddate, U.startdate, username, contract, u.email, region
)A
获取错误:将varchar数据类型转换为日期时间数据类型会导致超出范围的值。
如何使用将来的日期?
答案 0 :(得分:0)
所以你有2月的无效日期。
我会看一下EOMONTH(月末)函数https://msdn.microsoft.com/en-us/library/hh213020.aspx
所以你可以在本月的第一天通过,SQL将解决剩下的问题。