sqlite - 在 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,但我不明白为什么。我究竟做错了什么?提前感谢您的任何建议。
解决方案
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
推荐阅读
- python - 功能字节编码相同的输入并具有不同的响应
- ios - 尝试从应用程序快速发送电子邮件
- javascript - 如何在 JavaScript 中将数组元素放在网格模板区域内
- rust - 对 Vec 元素的可变引用以及结构和参数的生命周期
- runtime-error - 计数排序技术对我不起作用。来自 abort(3) (SIGABRT) 的运行时错误中止信号
- python - 使用 python selenium 从谷歌表单下拉列表中选择一个选项
- pandas - 如何从单元格中的多个值中提取最高值?
- c++ - exit(0) 和 raise(SIGTERM) 有什么区别
- javascript - 如何从 for 循环中获取变量并在循环外使用它
- javascript - 如何检查字符串是否在 JavaScript 中具有相同的字符?