记下一条使用T-SQL中日期函数比较多的一个SQL语句:
SELECT * FROM XkzsQsID where 1=1and id in (SELECT top 4294967000 MAX(ID) AS id FROM XkzsQsID GROUP BY QsID ORDER BY MAX(ID))
and islogout is null and not ((YouXRQ < getdate() and (islogout is null OR IsLogout <> 1)) or ((YouXRQ < DATEADD(Month, 6,
GETDATE())) AND (IsLogout IS NULL) AND (YouXRQ > GETDATE())) or ( (DATEPART(year, DATEADD(month, 11, FaZRQ)) = DATEPART(year,
GETDATE())) AND DATEPART(month, DATEADD(month, 11, FaZRQ)) = DATEPART(month, GETDATE()) OR (DATEPART(year, DATEADD(month, 23,
FaZRQ)) = DATEPART(year, GETDATE())) AND (DATEPART(month, DATEADD(month, 23, FaZRQ)) = DATEPART(month, GETDATE())) ))