Thursday, April 23, 2015

I am selecting BP(sys/dia) from a table. I want the values split into two separate columns.


I have table with BP(SYS/DIA) information , i am trying to split the SYS , DIA values into 2 different columns
and select the min value of each filed. but when i am selecting the min value i am not getting the in values.
hope below sql helps to understand more
CREATE TABLE #BP_INFO

(ID INT , NAME VARCHAR(10), BP VARCHAR(10))

INSERT INTO #BP_INFO
VALUES(1,'ABC','100/60')
,(2,'XYZ','120/70')
,(3,'GHD','110/101')
SELECT * FROM #BP_INFO
I have this following query ,but this is not giving me the right answer.

DROP TABLE #ABC
SELECT ID, NAME
, PARSENAME(REPLACE(BP,'/','.'),1) AS BP_SYS
, PARSENAME(REPLACE(BP,'/','.'),1) AS BP_DIA
INTO #ABC
FROM #BP_INFO

select min(bp_sys) from #ABC
select min(bp_dia) from #ABC

when i run the above select statement for bp_dia , i am not getting the minimum value .
Thanks in advance

No comments:

Post a Comment