Herewith, I am giving you one more example of OUTPUT parameter in Stored Procedure for calculating BSA (Body Surface Area). You are in development of medical software than BSA is not a new term for you. If your body surface are is between 1 to 2 than it is normal as per my little knowledge about BSA. I am giving a sample example which will calculate BSA based on the given height and weight. Height and Weight should be either in kg (weight) and cm (height) or in lbs (weight) and inch (height). You can make it more customize by giving more dynamic conversions.
--CREATING stored procedure to return BSA (Body Surface Area)
--The calculation is from the formula of DuBois and DuBois:
--BSA = (W 0.425 x H 0.725) x 0.007184
--where the weight is in kilograms and the height is in centimeters.
--
--
--DuBois D, DuBois EF. A formula to estimate the approximate surface area
--if height and weight be known. Arch Intern Medicine. 1916; 17:863-71.
--Wang Y, Moss J, Thisted R. Predictors of body surface area.
CREATE PROC CalcBSA
@option INT,
@weight FLOAT,
@height FLOAT,
@bsa FLOAT OUTPUT
AS
SET NOCOUNT ON
--if weight and height are in kg and cm accordingly
IF @option=1
BEGIN
SET @bsa=power(@weight,0.425)*power(@height,0.725)*0.007184
END
--if weight and height are in lbs and inch accordigly
ELSE
BEGIN
SET @weight=(@weight/2.2046)
SET @height=@height*2.54
SET @bsa=power(@weight,0.425)*power(@height,0.725)*0.007184
END
GO
--once you done with creating stored procedure, let us see whether actually it works!!!!
DECLARE @BSA FLOAT
EXECUTE calcbsa 1,84,180,@BSA OUTPUT
PRINT @BSA
GO
If you are new to stored procedure and wants to study it than do have a look at my following basic articles. Those articles contain from basic definition of stored procedure to different usage of SP.
http://www.sqlhub.com/2009/03/stored-procedure-in-microsoft-sql.html
http://www.sqlhub.com/2009/03/return-data-with-output-parameter-from.html
http://www.sqlhub.com/2009/03/dml-insert-with-multiple-ways-in-sql.html
http://www.sqlhub.com/2009/03/delete-many-multiple-records-in-bunch.html
http://www.sqlhub.com/2009/03/startup-stored-procedure-sql-server.html
http://www.sqlhub.com/2009/03/create-your-own-system-stored-procedure.html
Reference: Ritesh Shah
http://www.SQLHub.Com
Note: Microsoft Books online is a default reference of all articles but examples and explanations prepared by Ritesh Shah, founder of http://www.SQLHub.com
0 comments:
Post a Comment