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

时间:2022-11-15 17:07:38

I'm using phpmyadmin and I have the following stored procedure:

我正在使用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 value is insert by the user.

p_id值由用户插入。

In some records im.resolution_circumstances is null. When I call the stored procedure I want to find if it's null and return the value N/A. I only want to return the value and not to store it to the specific field in the database.

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

Do you have any idea?

你有什么主意吗?

1 个解决方案

#1


1  

You can use case to check whether your property is null or not

您可以使用大小写来检查您的属性是否为null

 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()

#1


1  

You can use case to check whether your property is null or not

您可以使用大小写来检查您的属性是否为null

 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()