Msg 245,Level 16,State 1,Line 1

时间:2013-10-10 15:55:01

标签: sql-server-2008 join count report

我正在尝试根据某些标准进行计数,但我无法使标准正确。

  • 排除账户类型:(8)非会员债券赎回; (15)遗产限制; (16)不受限制的房地产和(17)经销商直接。
  • 排除包含警告代码50的帐户和已关闭90天或更长时间的共享ID 01
  • 排除死者
  • 排除重复的社会安全号码

这是我的疑问:

;with records as
(
select AD.AccountNumber AS ACCOUNT_NUMBER,
       SD.ShareType AS TYPE,
       SD.SharePrimeNameSSN AS SSN,
       AD.AccountPrimeLongName AS NAME,
       SD.PROCESSDATE AS DATE,
row_number() over (partition by SD.sharePrimeNameSSN
order by SD.SHARETYPE ASC) N      
from arcu.ARCUAccountDetailed AD
join arcu.ARCUShareDetailed SD
on AD.accountnumber = sd.accountnumber AND
AD.ProcessDate = SD.ProcessDate
where 
AD.AccountPrimeNameDeathDate IS NULL AND
AD.AccountStatus = 'OPEN' AND
SD.ShareStatus = 'OPEN' AND
(SD.ShareType != '8' AND SD.ShareType != '15' AND SD.ShareType != '16'
AND SD.ShareType != '17') AND
(((AccountWarningcode1  != '50' AND
AccountWarningcode2  != '50' AND
AccountWarningcode3  != '50' AND
AccountWarningcode4  != '50' AND
AccountWarningcode5  != '50' AND
AccountWarningcode6  != '50' AND
AccountWarningcode7  != '50' AND
AccountWarningcode8  != '50' AND
AccountWarningcode9  != '50' AND
AccountWarningcode10 != '50' AND
AccountWarningcode11 != '50' AND
AccountWarningcode12 != '50' AND
AccountWarningcode13 != '50' AND
AccountWarningcode14 != '50' AND
AccountWarningcode15 != '50' AND
AccountWarningcode16 != '50' AND
AccountWarningcode17 != '50' AND
AccountWarningcode18 != '50' AND
AccountWarningcode19 != '50' AND
AccountWarningcode20 != '50') AND 
(ShareID = 001 AND ShareCloseDate >= (GetDate() - 90)))
AND
AccountPrimeNameDeathDate is null
))
select Count(*) from records
where N = 1

我收到以下错误

Msg 245, Level 16, State 1, Line 1
Conversion failed when converting the varchar value '5.00' to data type int.

1 个答案:

答案 0 :(得分:0)

我认为您的ShareID不是数字字段,错误来自:

ShareID = 001 

你可能想要

ShareID = '001'