首页 > 解决方案 > Using Cast to Convert DateTime to Date and select today's date

问题描述

I'm trying to count the number of accounts opened on today's date in the SELECT Statement. I'm doing so with an IIF statement and using CAST to convert the DateTimeStamp to Date. That said, I'm having trouble figuring out where to date column (Open_Date) and how to check to see if it's is today's date. Would I place -1 right after the ) following as date or???

COUNT(IIF(CAST(GETDATE() AS date))), SHARE.MEMBER_NBR, null)) AS ALLNEWACCOUNTSTODAY

标签: sqlreportbuilder3.0

解决方案


You can use case expression with Open_Date :

COUNT(CASE WHEN CONVERT(DATE, GETDATE()) = Open_Date THEN SHARE.MEMBER_NBR END) AS ALLNEWACCOUNTSTODAY

推荐阅读