2

After I run my select statement I get the following values "see image"

I would like to have a case statement to check if BloodPressureSystolic == 0 and if so, then pull the values from BPSRSit and BPSRSit and add then add the values to the temp table like this "115/65" can someone show me how to write a case like that.

data returned after select

Here is my select statement that I would like to add a case statement to

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 )
1
  • 2
    Using implict joins is a sql antiptttern. You should stop using them. Commented Aug 27, 2013 at 19:09

2 Answers 2

4
 CASE WHEN BloodPressureSystolic = 0 AND BloodPressureDiastolic = 0 THEN
      CAST(BPSRSit AS VARCHAR(10)) + '/' + CAST(BPDRSit AS VARCHAR(10)) END
Sign up to request clarification or add additional context in comments.

4 Comments

should i add this "END AS Temp" so i get the data into temp
(CASE WHEN BloodPressureSystolic = 0 AND BloodPressureDiastolic = 0 THEN CONVERT(VARCHAR(10),BPSRSit) + '/' + CONVERT(VARCHAR(10),BPDRSit) END)TEMP
how about when BloodPressureSystolic != 0 AND BloodPressureDiastolic != 0. can i have to two case in one select?
Yes you can! CASE WHEN BloodPressureSystolic = 0 AND BloodPressureDiastolic = 0 THEN CAST(BPSRSit AS VARCHAR(10)) + '/' + CAST(BPDRSit AS VARCHAR(10)) WHEN BloodPressureSystolic <> 0 AND BloodPressureDiastolic <> 0 THEN ...do something ... END
0

For MySQL you have two options in using the CASE statment. http://dev.mysql.com/doc/refman/5.0/en/case.html

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

OR

CASE WHEN [search conditions] THEN [output] END

About you question you could use something like this:

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)

1 Comment

But the user is not asking that how it could be done in MySQL. And also your query is wrong and wont get the required output.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.