2011-03-08 99 views

回答

3

如果你它們導入到SQL Server表

update tbl 
set theColumn = NULL 
WHERE theColumn = 'NaN' 

,如果它們是字符串「男」 對於列包含'南的這列的值轉換爲NULL,它必須是VARCHAR ,所以如果你喜歡0,這將是字符串 '0'

update tbl 
set theColumn = '0' 
WHERE theColumn = 'NaN' 

在SELECT語句中,你可以使用的

SELECT NULLIF(theColumn, 'NaN') as NullifiedTheColumn, ... 
SELECT CASE theColumn when 'NaN' then '0' else theColumn end as ZeroedTheColumn, ... 
+0

和轉換到零?? – cMinor 2011-03-08 20:17:06

2

CASE WHEN IsNumeric(column)=0 THEN 0 ELSE column怎麼樣?

+0

它在「Select語句」中看起來如何? – cMinor 2011-03-08 20:18:14

+0

當IsNumeric(column)= 0時的SELECT CASE THEN 0 ELSE column END' – 2011-03-08 20:20:56

+0

運行此:-) SELECT IsNUMERIC('2d4') – SQLMenace 2011-03-08 20:22:09

1
SELECT NULLIF('NaN', ColumnName) 

例如

DECLARE @d VARCHAR(3) ='NaN' 

SELECT NULLIF('NaN', @d) 

爲0

DECLARE @d VARCHAR(7) ='NaN' 

SELECT CASE WHEN @d = 'NaN' THEN '0' ELSE @d END