Max Value Between Two Different Names
Hello All,
I am trying to figure out how to do this. I want to get the max value of the 'BUN' result which I know how to do. I also want to get the max value between the Glucose IDG and Glucose Fasting. I haven't been able to figure it out.
The results should be:
1234 10/13/2010 17:00:00 BUN 25
1234 10/14/2010 06:00:00 Glucose Fasting 90
Any help will be appreciated.
Tony
--------------------------------------------
USE TempDB
GO
CREATE TABLE dbo.labdata
(
UserID INT,
TestDate DATETIME,
TestName VARCHAR(100),
TestResult INT
)
INSERT INTO LabData
(TestNbr,TestDate,TestName,TestResult)
SELECT '1234','10/14/2010 18:00:00','BUN','20' UNION ALL
SELECT '1234','10/13/2010 17:00:00','BUN','25' UNION ALL
SELECT '1234','10/14/2010 13:00:00','Glucose IDG','80' UNION ALL
SELECT '1234','10/14/2010 06:00:00','Glucose Fasting','90'
|