首页 > 解决方案 > 在 SQLite 中解析为零的情况

问题描述

SQLite在我的 .NET 应用程序中使用,我有以下查询:

select (CASE IFNULL(CCODE_1, '') when 'STD' then '_' else '' end) + 
(CASE IFNULL(CFRRR_CS, '') when '1' then 'F_' when '2' then 'R_' when '3' then 'FR_' else '' end) + 
IFNULL(CCODE_1, '') +
(CASE when (IFNULL(CCODE_2, '') = '') then '' else '_' end) + 
IFNULL(CCODE_2, '') +
(CASE when (IFNULL(CCODE_3, '') = '') then '' else '_' end) + 
IFNULL(CCODE_3, '') as OptionID
from X20_TIRES

上面的查询产生一个OptionID全 0 的列。没有其他的。

以下是来自 X20_TIRES 的一些示例数据:

在此处输入图像描述

我期待如下结果:

R_F41A
R_F41V
etc...

我很清楚,它case/when/then正在崩溃并简单地吐出 0,但我不明白为什么。我究竟做错了什么?提前感谢您的任何建议。

标签: sqlite

解决方案


If you want to concatenate all these results from the CASE statements,
you must use the || operator instead of +:

select 
  (CASE IFNULL(CCODE_1, '') when 'STD' then '_' else '' end) || 
(CASE IFNULL(CFRRR_CS, '') when '1' then 'F_' when '2' then 'R_' when '3' then 'FR_' else '' end) || 
IFNULL(CCODE_1, '') ||
(CASE when (IFNULL(CCODE_2, '') = '') then '' else '_' end) || 
IFNULL(CCODE_2, '') ||
(CASE when (IFNULL(CCODE_3, '') = '') then '' else '_' end) || 
IFNULL(CCODE_3, '') as OptionID
from X20_TIRES

推荐阅读