2

运行我的选择语句后,我得到以下值“见图片”

我想有一个case语句来检查是否BloodPressureSystolic == 0和如果是这样,然后从BPSRSitBPSRSit添加值然后将值添加到临时表中,就像这样“115/65”有人可以告诉我如何编写这样的案例。

选择后返回的数据

这是我的选择语句,我想在其中添加一个案例语句

SELECT  ad.ApptDate ,
    ISNULL(v.Temperature, 0) AS Temperature ,
    ISNULL(v.PS, 0) AS PerfStatus ,
    v.*
FROM    vitals v ,
    AppointmentData ad
WHERE   v.PatientId = 11
    AND ad.ApptId = v.ScheduleId
    AND ad.ApptDate < GETDATE()
    AND ad.StatusId NOT IN ( 3, 8 )
4

2 回答 2

4
 CASE WHEN BloodPressureSystolic = 0 AND BloodPressureDiastolic = 0 THEN
      CAST(BPSRSit AS VARCHAR(10)) + '/' + CAST(BPDRSit AS VARCHAR(10)) END
于 2013-08-27T19:07:32.620 回答
0

对于 MySQL,您有两个使用 CASE 语句的选项。http://dev.mysql.com/doc/refman/5.0/en/case.html

CASE [case value] WHEN [value] THEN [output] END

或者

CASE WHEN [search conditions] THEN [output] END

关于您的问题,您可以使用以下内容:

select ad.ApptDate ,
    ISNULL(v.Temperature, 0) as Temperature, 
    ISNULL(v.PS, 0) as PerfStatus,
    v.*, 
    CASE WHEN (BloodPressureSystolic = 0 AND BloodPressureDiastolic = 0) THEN CONCAT(BPSRSit, "/", BPDRSit) END AS myOutput 
from vitals v,AppointmentData ad
Where v.PatientId = 11
    And ad.ApptId = v.ScheduleId
    and ad.ApptDate < GETDATE()
    and ad.StatusId not in (3,8)
于 2013-08-27T19:19:34.353 回答