MySQL:如果存储过程中的选定字段具有 NULL 值,我想返回 N/A 作为值

标签 mysql stored-procedures phpmyadmin

我正在使用 phpmyadmin 并且我有以下存储过程:

SELECT im.onset_date,
im.end_date,
im.coding_id,
im.patient_id,
im.resolution_circumstances, 
FROM illness_mapping as im
WHERE im.patient_id = p_id and im.end_date <= CURDATE()

p_id 值由用户插入。

在某些记录中,im.resolution_circumstances 为空。当我调用存储过程时,我想查找它是否为空并返回值N/A。我只想返回值,而不是将其存储到数据库中的特定字段。

你有什么想法吗?

最佳答案

您可以使用case来检查您的属性是否为空

 SELECT im.onset_date,
    im.end_date,
    im.coding_id,
    im.patient_id,
(case 
    when im.resolution_circumstances is null 
       then "N/A"
    when im.resolution_circumstances is not null 
       then im.resolution_circumstances
  end) as resolution_circumstances
    FROM illness_mapping as im
    WHERE im.patient_id = p_id and im.end_date <= CURDATE()

关于MySQL:如果存储过程中的选定字段具有 NULL 值,我想返回 N/A 作为值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46092188/

相关文章:

php - MySql 删除不工作

c# - 在 ASP.net C# Web 表单 Web 应用程序中自动访问和关闭数据库

C# - 批量执行存储过程

php - 当我没有主机的 'create' 权限时,如何在 mysql 数据库中创建表?

php - 需要更新 mySQL 表列中缺失的信息

满足条件的 PHP 查询必须出现在第二个表中

php - 改进我的 Zend 存储过程调用代码

MySQL 触发器通过重新排序其值来更新列

mysql - Row 不想在 mysql 中添加更多表,因为时间戳

php - 使用 PHP 导出 MySQL 数据库