Sql var char每次都去其他地方

时间:2015-09-24 18:32:07

标签: sql sql-server

我正在尝试将2更改为Complete,2是varchar值 但每次进入else子句

CASE [consent_complete]
  WHEN  '2'  THEN 'Complete'  
  ELSE 'IN Complete'
END AS  'Complete?'

1 个答案:

答案 0 :(得分:3)

我怀疑你的数据最后有空格和/或\0字符:

SELECT ...
   CASE  
     WHEN LEFT(LTRIM(RTRIM([consent_complete])),1) = '2' THEN 'Complete'  
     ELSE 'Incomplete'
   END AS  [Complete?]
FROM ...

此外,您应该清理数据TRIM空格和REPLACE \0字符。