请参阅屏幕截图:
您将如何编写case语句来识别小数点后只有零的记录。
这是我的select case语句的结构如下:
SELECT CASE WHEN (ONLY ZEROS AFTER
DECIMAL POINT)
THEN CAST(VALUE AS int) FROM MyTable
我之所以保留varchar(25)
只是因为还有两个字段需要与上述数字组合。
答案 0 :(得分:3)
一种方法是:
'The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
答案 1 :(得分:1)
您可以执行与Gordon答案类似的操作,但是要考虑到您将数字存储为varchar(25)
declare @mytable table (value varchar(25) not null)
insert into @mytable (value) values ('1.31'),('5.00'),('2.500'),('6.00'),('8.0000'),('1.0'),('3.0000000')
select coalesce(cast((case when DecimalValue = floor(DecimalValue) then cast(DecimalValue as int) end) as varchar(25)), VarcharValue)
from (select cast(value as decimal(18,9)) as DecimalValue, value as VarcharValue from @mytable) as tmp