我有一個表:SQL服務器:錯誤的數據類型爲varchar轉換爲數字
Account_Code | Desc
503100 | account xxx
503103 | account xxx
503104 | account xxx
503102A | account xxx
503110B | account xxx
凡Account_Code
是varchar
。
當我創建以下查詢:
Select
cast(account_code as numeric(20,0)) as account_code,
descr
from account
where isnumeric(account_code) = 1
它通過返回在account_code
列一個有效的數值都記錄運行良好。
但是當我嘗試添加另一種選擇,嵌套前SQL:
select account_code,descr
from
(
Select cast(account_code as numeric(20, 0)) as account_code,descr
from account
where isnumeric(account_code) = 1
) a
WHERE account_code between 503100 and 503105
查詢將返回一個錯誤
錯誤轉換數據類型爲varchar到數字。
這是怎麼回事呢?
我已如果account_code
有效已經轉換爲數字,但似乎查詢仍在努力處理非有效的記錄。
我需要使用BETWEEN
子句中我的查詢。
什麼版本的SQL Server? – ErikE