| Author |
Topic |
|
pk_bohra
Master Smack Fu Yak Hacker
1182 Posts |
Posted - 2008-12-09 : 08:53:41
|
| Hi All,The below is the sample data from a table. My requirement is to store the maximum value of BP Max and Value of BP Min (against the BP Max).DateofRecording ------ BP Max ------ BP Min ------------ Required Output15-Oct-08 ------ 120 ------ 65 ------------ 150/7015-Oct-08 ------ 130 ------ 75 ------------ 150/7015-Oct-08 ------ 150 ------ 70 ------------ 150/7015-Oct-08 ------ 100 ------ 120 ------------ 150/70 16-Oct-08 ------ 140 ------ 60 ------------ 140/6016-Oct-08 ------ 120 ------ 80 ------------ 140/6016-Oct-08 ------ 135 ------ 75 ------------ 140/60 17-Oct-08 ------ 140 ------ 80 ------------ 140/80Thanks in advance.Bohra |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-09 : 09:40:00
|
| [code]SELECT DateofRecording,[BP Max] ,[BP Min],CAST(MAX([BP Max]) OVER (PARTITION BY DateofRecording) AS varchar(10)) + CAST(MIN([BP Min]) OVER (PARTITION BY DateofRecording) AS varchar(10)) AS NewColumnFROM YourTable[/code] |
 |
|
|
pk_bohra
Master Smack Fu Yak Hacker
1182 Posts |
Posted - 2008-12-09 : 10:19:05
|
| Hi Visakh,I tried the query given by you. It is giving me maximum and minimum for the given date. Ex: For 15-Oct-08, it is returning 150/65. The value I want for 15-Oct-08 is 150/70.Thanks Bohra |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-09 : 10:28:33
|
quote: Originally posted by pk_bohra Hi Visakh,I tried the query given by you. It is giving me maximum and minimum for the given date. Ex: For 15-Oct-08, it is returning 150/65. The value I want for 15-Oct-08 is 150/70.Thanks Bohra
then what's value you're looking at?whats the significance of 70 ? |
 |
|
|
pk_bohra
Master Smack Fu Yak Hacker
1182 Posts |
Posted - 2008-12-09 : 10:38:16
|
| Hi Visakh,The two columns, BP Max & BP Min stands for BloodPressure (maximum) & BloodPressure(Minimum). This two values makes a pair.The database is of a hospital.Doctors will be interested in knowing the lower side of blood pressure ( which belongs to maximum value).The significance of 70 is that it is the lower side of blood pressure when the higher side was at 150.If i show 150/65, it won't be correct as the lower side value was 70 (Value of BP Min column).If the description is not clear then please feel free to clarify.Thanks again,Bohra |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-09 : 10:50:20
|
| [code]SELECT t.DateofRecording,t.[BP Max],t.[BP Min],CAST(t.MaxBP AS varchar(10)) + CAST(t1.[BP Min] AS varchar(10)) AS NewColumnFROM(SELECT DateofRecording,[BP Max] ,[BP Min],MAX([BP Max]) OVER (PARTITION BY DateofRecording) AS MaxBPFROM YourTable )tCROSS APPLY (SELECT [BP Min] FROM YourTable WHERE DateofRecording=t.DateofRecording AND [BP Max]=t. MaxBP)t1[/code] |
 |
|
|
pk_bohra
Master Smack Fu Yak Hacker
1182 Posts |
Posted - 2008-12-09 : 10:57:07
|
| Hi Visakh,Your query gave me the exact solution which i was looking for.Many many thanks to you.Regards,Bohra |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-09 : 10:59:38
|
Cheers |
 |
|
|
|