Thursday, April 23, 2015

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

There are other ways, for example
SELECT
        LEFT(BP,CHARINDEX('/',BP)-1) AS BP_SYS,
        STUFF(BP,1,CHARINDEX('/',BP),'') AS BP_DIA
FROM
        #BP_INFO
If you happen to have records which have no / character in the BP column, this will fail, but I guess everyone has to have systolic and a diastolic, so that is not a problem for you. But if that can happen, you have to program to account for that.

No comments:

Post a Comment