运行此查询时收到错误消息147。我正在寻找注释包含DBA且未过期或过期日期为空的所有记录,但我需要查看具有此条件的最新记录。我也不确定如何格式化日期以获取“2013-09-18 00:00:00”格式的当前日期,以便查询可以随时运行而无需硬编码日期。我的select语句中也有MIN(),因为它让我感到内疚...那还有什么东西我应该用来替代它吗?
SELECT
AD.AccountNumber AS ACCOUNTNUMBER,
MIN(AD.SharePrimeNameLongName) AS NAME,
MIN(AD.SharePrimeNameSSN) AS SSN,
MIN(AD.SharePrimeNameSSNType) AS SSNTYPE,
MIN(C.COMMENT) AS COMMENT
FROM
ARCU.ARCUShareDetailed AS AD JOIN
COMMENT AS C ON
AD.AccountNumber = C.PARENTACCOUNT
WHERE
AD.AccountStatus = 'OPEN' AND
(C.ProcessDate = (Select MAX(AD.ProcessDate) from COMMENT having
C.COMMENT Like '%DBA') AND
((C.EXPIRATIONDATE > '2013-09-18 00:00:00') OR
(C.EXPIRATIONDATE IS NULL)))
ORDER BY AccountNumber
答案 0 :(得分:1)
如果选项中的AD.AccountNumber
没有GROUP BY
或HAVING
条款,则会收到错误147。
至于日期,如果你想要任何比午夜更大的东西,你可以使用CONVERT(date, GETDATE())