CONVERSION OF 1 TABLE TO ACCOMODATE MORE FIELDS USING TEMP VARIABLE IN STORE PROC

USE [FacetsXR]
GO
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[frdmrpt].[pr_pha_BiometricsSummary]') AND type in (N'P', N'PC'))
DROP PROCEDURE [frdmrpt].[pr_pha_BiometricsSummary]
GO
CREATE PROCEDURE [frdmrpt].[pr_pha_BiometricsSummary]
AS
BEGIN
DECLARE @partcTot int
select @partcTot = [frdmrpt].[fn_pha_total_participants](default);
DECLARE @TEMPTAB TABLE
SortOrder varchar(10),
BIMEASURE VARCHAR(30) NULL,
RC VARCHAR(100) NULL,
N VARCHAR(5) NULL,
PSP VARCHAR(10) NULL,
AVL VARCHAR(10) NULL
-- HEADER ROW
--INSERT @TEMPTAB VALUES('00','Biometric Measure','Risk Citeria','N','Percent Of Screened Population','Average Value')
--BMI
declare @BMI int
select @BMI = count(*)
FROM [frdmrpt].[wt_rpt_pha_pw_HRADetail2] hra
INNER JOIN [frdmrpt].[wt_rpt_pha_pw_Member] mems
ON hra.UserID = mems.UserID
WHERE hra.BMI is not null and hra.BMI != 0.0
declare @BMIavg float
select @BMIavg = cast(isnull(AVG(BMI),0.0) as decimal (5,1))
FROM [frdmrpt].[wt_rpt_pha_pw_HRADetail2] hra
INNER JOIN [frdmrpt].[wt_rpt_pha_pw_Member] mems
ON hra.UserID = mems.UserID
WHERE hra.BMI is not null
INSERT @TEMPTAB VALUES('100','BMI','.',@BMI,'.',@BMIavg)
INSERT @TEMPTAB
SELECT SortOrder,RiskCriteria, BS.Risk_Criteria,COUNT(*) Total,CAST((CAST(([frdmrpt].[fn_pha_percent](COUNT(*), @BMI)) AS VARCHAR(100))) AS VARCHAR(100))+'%'
FROM
SELECT
CASE
WHEN (BMI > 0 AND BMI <= 17.4) THEN '101'
WHEN BMI BETWEEN 17.5 AND 18.4 THEN '102'
WHEN BMI BETWEEN 18.5 AND 24.9 THEN '103'
WHEN BMI BETWEEN 25.0 AND 29.9 THEN '104'
WHEN BMI >=30.0 THEN '105'
END AS SortOrder,
CASE
WHEN (BMI > 0 AND BMI <= 17.4) THEN 'Very Underweight'
WHEN BMI BETWEEN 17.5 AND 18.4 THEN 'Underweight'
WHEN BMI BETWEEN 18.5 AND 24.9 THEN 'Normal'
WHEN BMI BETWEEN 25.0 AND 29.9 THEN 'Overweight'
WHEN BMI >=30.0 THEN 'Obese'
END AS RiskCriteria
FROM [frdmrpt].[wt_rpt_pha_pw_HRADetail2] hra
INNER JOIN [frdmrpt].[wt_rpt_pha_pw_Member] mems
ON hra.UserID = mems.UserID
) bioSumBI
INNER JOIN [frdmrpt].[pw_Biometric_Summary] BS
ON bioSumBI.RiskCriteria = BS.Bimetric_Measure
AND BS.Bimetric_Category ='BMI'
WHERE bioSumBI.RiskCriteria is not null
GROUP BY bioSumBI.SortOrder ,bioSumBI.RiskCriteria,BS.Risk_Criteria,BS.Risk_Higher_Limit
ORDER BY BS.Risk_Higher_Limit
IF (Select COUNT(*) from @TEMPTAB where SortOrder ='101') = 0
INSERT @TEMPTAB VALUES('101','Very Underweight','17.4 and below','0','0%','.')
IF (Select COUNT(*) from @TEMPTAB where SortOrder ='102') = 0
INSERT @TEMPTAB VALUES('102','Underweight','17.5 to 18.4','0','0%','.')
IF (Select COUNT(*) from @TEMPTAB where SortOrder ='103') = 0
INSERT @TEMPTAB VALUES('103','Normal','18.5 to 24.9','0','0%','.')
IF (Select COUNT(*) from @TEMPTAB where SortOrder ='104') = 0
INSERT @TEMPTAB VALUES('104','Overweight','25 to 29.9','0','0%','.')
IF (Select COUNT(*) from @TEMPTAB where SortOrder ='105') = 0
INSERT @TEMPTAB VALUES('105','Obese','30.0 and above','0','0%','.')
--BP
declare @BP INT
select @BP = count(*)
FROM [frdmrpt].[wt_rpt_pha_pw_HRADetail2] hra
INNER JOIN [frdmrpt].[wt_rpt_pha_pw_Member] mems
ON hra.UserID = mems.UserID
WHERE hra.Systolic IS NOT NULL AND hra.Diastolic IS NOT NULL
declare @BPAVG VARCHAR(15)
select @BPAVG = isnull(CONVERT(VARCHAR(15),AVG(Systolic)) + '/' + CONVERT(VARCHAR(5),AVG(Diastolic)),0)
FROM [frdmrpt].[wt_rpt_pha_pw_HRADetail2] hra
INNER JOIN [frdmrpt].[wt_rpt_pha_pw_Member] mems
ON hra.UserID = mems.UserID
WHERE hra.Systolic IS NOT NULL AND hra.Diastolic IS NOT NULL
INSERT @TEMPTAB VALUES('200','Blood Pressure (mmHg)','.',@BP,'.',@BPAVG)
INSERT @TEMPTAB
SELECT SortOrder ,RiskCriteria, BS.Risk_Criteria,COUNT(*) Total,
CAST(([frdmrpt].[fn_pha_percent](COUNT(*), @BP)) AS VARCHAR(100))+'%','.'
FROM
SELECT
CASE
WHEN (Systolic <=119 and Diastolic <=79) THEN 201
WHEN not (Systolic >= 140 OR Diastolic >=90) and not (Systolic <=119 and Diastolic <=79) THEN 202 -- basically not high and not low
WHEN (Systolic >= 140 OR Diastolic >=90) THEN 203
--WHEN hra.Systolic <=119 OR hra.Diastolic <=79 THEN '201'
--WHEN (hra.Systolic between 120 AND 139) OR (hra.Diastolic between 80 AND 89) THEN '202'
--WHEN (hra.Systolic between 140 AND 159) OR (hra.Diastolic between 90 AND 99) THEN '203'
--WHEN hra.Systolic >= 160 OR hra.Diastolic >= 100 THEN '204'
END AS SortOrder,
CASE
WHEN (Systolic <=119 and Diastolic <=79) THEN 'Low Risk'
WHEN not (Systolic >= 140 OR Diastolic >=90) and not (Systolic <=119 and Diastolic <=79) THEN 'Moderate Risk'
WHEN (Systolic >= 140 OR Diastolic >=90) THEN 'High Risk'
--WHEN hra.Systolic <=119 OR hra.Diastolic <=79 THEN 'Low Risk'
--WHEN (hra.Systolic between 120 AND 139) OR (hra.Diastolic between 80 AND 89) THEN 'Prehypertension'
--WHEN (hra.Systolic between 140 AND 159) OR (hra.Diastolic between 90 AND 99) THEN 'Stage I hypertension'
--WHEN hra.Systolic >= 160 OR hra.Diastolic >= 100 THEN 'Stage II hypertension'
END AS RiskCriteria
FROM [frdmrpt].[wt_rpt_pha_pw_HRADetail2] hra
INNER JOIN [frdmrpt].[wt_rpt_pha_pw_Member] mems
ON hra.UserID = mems.UserID
) bioSumBP
INNER JOIN [frdmrpt].[pw_Biometric_Summary] BS
ON bioSumBP.RiskCriteria = BS.Bimetric_Measure
AND BS.Bimetric_Category ='Blood Pressure (mmHg)'
WHERE bioSumBP.RiskCriteria is not null
GROUP BY bioSumBP.SortOrder ,bioSumBP.RiskCriteria,BS.Risk_Criteria,BS.Risk_Higher_Limit
--ORDER BY BS.Risk_Higher_Limit desc
IF (Select COUNT(*) from @TEMPTAB where SortOrder ='201') = 0
INSERT @TEMPTAB VALUES('201','Low Risk','Systolic: 119 and below Diastolic: 79 and below','0','0%','.')
IF (Select COUNT(*) from @TEMPTAB where SortOrder ='202') = 0
INSERT @TEMPTAB VALUES('202','Moderate Risk','Systolic: 120 to 139 Diastolic: 80 to 89','0','0%','.')
IF (Select COUNT(*) from @TEMPTAB where SortOrder ='203') = 0
INSERT @TEMPTAB VALUES('203','High Risk','Systolic: 140 and above Diastolic: 90 and above','0','0%','.')
--Cholestrol
declare @TC int
select @TC = count(*)
FROM [frdmrpt].[wt_rpt_pha_pw_HRADetail2] hra
INNER JOIN [frdmrpt].[wt_rpt_pha_pw_Member] mems
ON hra.UserID = mems.UserID
WHERE hra.TotalCholesterol IS NOT NULL
declare @TCAVG FLOAT
select @TCAVG = isnull(ROUND(AVG(TotalCholesterol),0),0)
FROM [frdmrpt].[wt_rpt_pha_pw_HRADetail2] hra
INNER JOIN [frdmrpt].[wt_rpt_pha_pw_Member] mems
ON hra.UserID = mems.UserID
WHERE hra.TotalCholesterol IS NOT NULL
INSERT @TEMPTAB VALUES('300','Total Cholesterol (mg/dL)','.',@TC,'.',@TCAVG)
INSERT @TEMPTAB
SELECT SortOrder ,RiskCriteria, BS.Risk_Criteria,COUNT(*) Total,
CAST(([frdmrpt].[fn_pha_percent](COUNT(*), @TC)) AS VARCHAR(100))+'%','.'
FROM
SELECT
CASE
WHEN hra.TotalCholesterol <= 199 THEN '301'
WHEN hra.TotalCholesterol between 200 and 239 THEN '302'
WHEN hra.TotalCholesterol >=240 THEN '303'
END AS SortOrder,
CASE
WHEN hra.TotalCholesterol <= 199 THEN 'Low Risk'
WHEN hra.TotalCholesterol between 200 and 239 THEN 'Moderate Risk'
WHEN hra.TotalCholesterol >=240 THEN 'High Risk'
END AS RiskCriteria
FROM [frdmrpt].[wt_rpt_pha_pw_HRADetail2] hra
INNER JOIN [frdmrpt].[wt_rpt_pha_pw_Member] mems
ON hra.UserID = mems.UserID
) bioSumHDL
INNER JOIN [frdmrpt].[pw_Biometric_Summary] BS
ON bioSumHDL.RiskCriteria = BS.Bimetric_Measure
AND BS.Bimetric_Category ='Total Cholesterol (mg/dL)'
WHERE bioSumHDL.RiskCriteria is not null
GROUP BY bioSumHDL.SortOrder ,bioSumHDL.RiskCriteria,BS.Risk_Criteria,BS.Risk_Higher_Limit
ORDER BY BS.Risk_Higher_Limit
IF (Select COUNT(*) from @TEMPTAB where SortOrder ='301') = 0
INSERT @TEMPTAB VALUES('301','Low Risk','199 and below','0','0%','.')
IF (Select COUNT(*) from @TEMPTAB where SortOrder ='302') = 0
INSERT @TEMPTAB VALUES('302','Moderate Risk','200 to 239','0','0%','.')
IF (Select COUNT(*) from @TEMPTAB where SortOrder ='303') = 0
INSERT @TEMPTAB VALUES('303','High Risk','240 and above','0','0%','.')
--HDL
declare @HDL int
select @HDL = count(*)
FROM [frdmrpt].[wt_rpt_pha_pw_HRADetail2] hra
INNER JOIN [frdmrpt].[wt_rpt_pha_pw_Member] mems
ON hra.UserID = mems.UserID
WHERE HDL IS NOT NULL
declare @HDLAVG FLOAT
select @HDLAVG = isnull(ROUND(AVG(HDL),0),0)
FROM [frdmrpt].[wt_rpt_pha_pw_HRADetail2] hra
INNER JOIN [frdmrpt].[wt_rpt_pha_pw_Member] mems
ON hra.UserID = mems.UserID
WHERE HDL IS NOT NULL
INSERT @TEMPTAB VALUES('400','HDL (mg/dL)','.',@HDL,'.',@HDLAVG)
INSERT @TEMPTAB
SELECT SortOrder ,RiskCriteria, BS.Risk_Criteria,COUNT(*) Total,
CAST(([frdmrpt].[fn_pha_percent](COUNT(*), @HDL)) AS VARCHAR(100))+'%','.'
FROM
SELECT
CASE
WHEN hra.HDL >= 60 THEN '401'--'Desirable'
WHEN hra.HDL between 40 and 59 THEN '402' --'Borderline Risk'
WHEN hra.HDL <=39 THEN '403' --'Undesirable Risk'
END AS SortOrder,
CASE
WHEN hra.HDL >= 60 THEN 'Low Risk'--'Desirable'
WHEN hra.HDL between 40 and 59 THEN 'Moderate Risk' --'Borderline Risk'
WHEN hra.HDL <=39 THEN 'High Risk' --'Undesirable Risk'
END AS RiskCriteria
FROM [frdmrpt].[wt_rpt_pha_pw_HRADetail2] hra
INNER JOIN [frdmrpt].[wt_rpt_pha_pw_Member] mems
ON hra.UserID = mems.UserID
) bioSumHDL
INNER JOIN [frdmrpt].[pw_Biometric_Summary] BS
ON bioSumHDL.RiskCriteria = BS.Bimetric_Measure
AND BS.Bimetric_Category ='HDL (mg/dL)'
WHERE bioSumHDL.RiskCriteria is not null
GROUP BY bioSumHDL.SortOrder ,bioSumHDL.RiskCriteria,BS.Risk_Criteria,BS.Risk_Higher_Limit
ORDER BY BS.Risk_Higher_Limit desc
IF (Select COUNT(*) from @TEMPTAB where SortOrder ='401') = 0
INSERT @TEMPTAB VALUES('401','Low Risk','60 and above','0','0%','.')
IF (Select COUNT(*) from @TEMPTAB where SortOrder ='402') = 0
INSERT @TEMPTAB VALUES('402','Moderate Risk','40 to 59','0','0%','.')
IF (Select COUNT(*) from @TEMPTAB where SortOrder ='403') = 0
INSERT @TEMPTAB VALUES('403','High Risk','39 and below','0','0%','.')
--LDL
declare @LDL DECIMAL
select @LDL = count(*)
FROM [frdmrpt].[wt_rpt_pha_pw_HRADetail2] hra
INNER JOIN [frdmrpt].[wt_rpt_pha_pw_Member] mems
ON hra.UserID = mems.UserID
WHERE hra.LDL IS NOT NULL
declare @LDLAVG FLOAT
select @LDLAVG = isnull(ROUND(AVG(LDL),0),0)
FROM [frdmrpt].[wt_rpt_pha_pw_HRADetail2] hra
INNER JOIN [frdmrpt].[wt_rpt_pha_pw_Member] mems
ON hra.UserID = mems.UserID
WHERE hra.LDL IS NOT NULL
INSERT @TEMPTAB VALUES('500','LDL (mg/dL)','.',@LDL,'.',@LDLAVG)
INSERT @TEMPTAB
SELECT SortOrder ,RiskCriteria, BS.Risk_Criteria,COUNT(*) Total,
CAST(([frdmrpt].[fn_pha_percent](COUNT(*), @LDL)) AS VARCHAR(100))+'%','.'
FROM
SELECT
CASE
WHEN hra.LDL <= 129 THEN '501'
WHEN hra.LDL between 130 and 159 THEN '502' --'Borderline Risk'
WHEN hra.LDL >=160 THEN '503' --'Undesirable Risk'
END AS SortOrder,
CASE
WHEN hra.LDL <= 129 THEN 'Low Risk'--'Desirable'
WHEN hra.LDL between 130 and 159 THEN 'Moderate Risk' --'Borderline Risk'
WHEN hra.LDL >=160 THEN 'High Risk' --'Undesirable Risk'
END AS RiskCriteria
FROM [frdmrpt].[wt_rpt_pha_pw_HRADetail2] hra
INNER JOIN [frdmrpt].[wt_rpt_pha_pw_Member] mems
ON hra.UserID = mems.UserID
) bioSumHDL
INNER JOIN [frdmrpt].[pw_Biometric_Summary] BS
ON bioSumHDL.RiskCriteria = BS.Bimetric_Measure
AND BS.Bimetric_Category ='LDL (mg/dL)'
WHERE bioSumHDL.RiskCriteria is not null
GROUP BY bioSumHDL.SortOrder ,bioSumHDL.RiskCriteria,BS.Risk_Criteria,BS.Risk_Higher_Limit
ORDER BY BS.Risk_Higher_Limit
IF (Select COUNT(*) from @TEMPTAB where SortOrder ='501') = 0
INSERT @TEMPTAB VALUES('501','Low Risk','129 and below','0','0%','.')
IF (Select COUNT(*) from @TEMPTAB where SortOrder ='502') = 0
INSERT @TEMPTAB VALUES('502','Moderate Risk','130 to 159','0','0%','.')
IF (Select COUNT(*) from @TEMPTAB where SortOrder ='503') = 0
INSERT @TEMPTAB VALUES('503','High Risk','160 and above','0','0%','.')
--Blood Glucose (mg/dL)
declare @BG int
select @BG = count(*)
FROM [frdmrpt].[wt_rpt_pha_pw_HRADetail2] hra
INNER JOIN [frdmrpt].[wt_rpt_pha_pw_Member] mems
ON hra.UserID = mems.UserID
WHERE hra.BloodGlucose IS NOT NULL
declare @BGAVG FLOAT
select @BGAVG = ROUND(AVG(BloodGlucose),0)
FROM [frdmrpt].[wt_rpt_pha_pw_HRADetail2] hra
INNER JOIN [frdmrpt].[wt_rpt_pha_pw_Member] mems
ON hra.UserID = mems.UserID
WHERE hra.BloodGlucose IS NOT NULL
INSERT @TEMPTAB VALUES('600','Blood Glucose (mg/dL)','.',@BG,'.','NA' )--@BGAVG)
INSERT @TEMPTAB
PRESENT CODE FOR ATTACHED TABLE SELECT SortOrder ,RiskCriteria, BS.Risk_Criteria, Total,
CAST(([frdmrpt].[fn_pha_percent](Total, @BG)) AS VARCHAR(100))+'%','.'
FROM
SELECT
CASE
WHEN (r.RiskLevel='LOW') THEN '601'
WHEN (r.RiskLevel='MODERATE') THEN '602'
WHEN (r.RiskLevel='HIGH') THEN '603'
END AS SortOrder,
CASE
WHEN (r.RiskLevel='LOW') THEN 'Low Risk'
WHEN (r.RiskLevel='MODERATE') THEN 'Moderate Risk'
WHEN (r.RiskLevel='HIGH') THEN 'High Risk'
END AS RiskCriteria,
CASE
WHEN (r.RiskLevel='LOW') THEN cast(COUNT(*)AS VARCHAR(100))
WHEN (r.RiskLevel='MODERATE') THEN cast(COUNT(*)AS VARCHAR(100))
WHEN (r.RiskLevel='HIGH') THEN cast(COUNT(*)AS VARCHAR(100))
END AS Total
From [frdmrpt].[wt_rpt_pha_pw_UserHealthRisks] r
join [frdmrpt].[wt_rpt_pha_pw_Member] m on m.UserID = r.UserID
join [frdmrpt].[wt_rpt_pha_pw_HRADetail2] d on d.UserID = m.UserID
where r.RiskStringID = 'BLOODGLUCOSE'
group by GROUPING sets ( r.RiskLevel, () )
) bioSumHDL
INNER JOIN [frdmrpt].[pw_Biometric_Summary] BS
ON bioSumHDL.RiskCriteria = BS.Bimetric_Measure
AND BS.Bimetric_Category ='Blood Glucose (mg/dL)'
WHERE bioSumHDL.RiskCriteria is not null
GROUP BY bioSumHDL.SortOrder ,bioSumHDL.Total,bioSumHDL.RiskCriteria,BS.Risk_Criteria,BS.Risk_Higher_Limit
ORDER BY BS.Risk_Higher_Limit
IF (Select COUNT(*) from @TEMPTAB where SortOrder ='601') = 0
INSERT @TEMPTAB VALUES('601','Low Risk','Fasting: 70 to 99 Random: 80 to 139','0','0%','.')
IF (Select COUNT(*) from @TEMPTAB where SortOrder ='602') = 0
INSERT @TEMPTAB VALUES('602','Moderate Risk','Fasting: 100 to 125 Random: 140 to 199','0','0%','.')
IF (Select COUNT(*) from @TEMPTAB where SortOrder ='603') = 0
INSERT @TEMPTAB VALUES('603','High Risk','Fasting: 126 and above Random: 200 and above','0','0%','.')
--Triglycerides (mg/dL)
declare @TRG int
select @TRG = count(*)
FROM [frdmrpt].[wt_rpt_pha_pw_HRADetail2] hra
INNER JOIN [frdmrpt].[wt_rpt_pha_pw_Member] mems
ON hra.UserID = mems.UserID
WHERE hra.Triglycerides IS NOT NULL
declare @TRGAVG FLOAT
select @TRGAVG = isnull(ROUND(AVG(Triglycerides),0),0)
FROM [frdmrpt].[wt_rpt_pha_pw_HRADetail2] hra
INNER JOIN [frdmrpt].[wt_rpt_pha_pw_Member] mems
ON hra.UserID = mems.UserID
WHERE hra.Triglycerides IS NOT NULL
INSERT @TEMPTAB VALUES('700','Triglycerides (mg/dL)','.',@TRG,'.',@TRGAVG)
INSERT @TEMPTAB
SELECT SortOrder ,RiskCriteria, BS.Risk_Criteria,COUNT(*) Total,
CAST(([frdmrpt].[fn_pha_percent](COUNT(*), @TRG)) AS VARCHAR(100))+'%','.'
FROM
SELECT
CASE
WHEN hra.Triglycerides <=149 THEN '701'
WHEN hra.Triglycerides between 150 and 199 THEN '702'
WHEN hra.Triglycerides >= 200 THEN '703'
END AS SortOrder,
CASE
WHEN hra.Triglycerides <=149 THEN 'Low Risk'
WHEN hra.Triglycerides between 150 and 199 THEN 'Moderate Risk'
WHEN hra.Triglycerides >= 200 THEN 'High Risk'
END AS RiskCriteria
FROM [frdmrpt].[wt_rpt_pha_pw_HRADetail2] hra
INNER JOIN [frdmrpt].[wt_rpt_pha_pw_Member] mems
ON hra.UserID = mems.UserID
) bioSumHDL
INNER JOIN [frdmrpt].[pw_Biometric_Summary] BS
ON bioSumHDL.RiskCriteria = BS.Bimetric_Measure
AND BS.Bimetric_Category ='Triglycerides (mg/dL)'
WHERE bioSumHDL.RiskCriteria is not null
GROUP BY bioSumHDL.SortOrder ,bioSumHDL.RiskCriteria,BS.Risk_Criteria,BS.Risk_Higher_Limit
ORDER BY BS.Risk_Higher_Limit
IF (Select COUNT(*) from @TEMPTAB where SortOrder ='701') = 0
INSERT @TEMPTAB VALUES('701','Low Risk','149 and below','0','0%','.')
IF (Select COUNT(*) from @TEMPTAB where SortOrder ='702') = 0
INSERT @TEMPTAB VALUES('702','Moderate Risk','150 to 199','0','0%','.')
IF (Select COUNT(*) from @TEMPTAB where SortOrder ='703') = 0
INSERT @TEMPTAB VALUES('703','High Risk','200 and above','0','0%','.')
SELECT BIMEASURE,RC ,N ,PSP ,AVL FROM @TEMPTAB order by SortOrder
END
GO
GRANT EXECUTE ON [frdmrpt].[pr_pha_BiometricsSummary] to FRDM_END_USER_ROLE
GO

work done so far(I will aprreciate your input and suggestions to complete this.Thanks
CREATE PROCEDURE [frdmrpt].[pr_pha_T1T2_BiometricsSummaryTest]
AS
BEGIN
DECLARE @partcTot int
select @partcTot = [frdmrpt].[fn_pha_total_participants](default);
DECLARE @TEMPTAB TABLE
SortOrder varchar(10),
BIMEASURE VARCHAR(30) NULL,
RC VARCHAR(100) NULL,
N_T1 VARCHAR(5) NULL,
PSP_T1 VARCHAR(10) NULL,
AVL_T1 VARCHAR(10) NULL,
N_T2 VARCHAR(5) NULL,
PSP_T2 VARCHAR(10) NULL,
AVL_T2 VARCHAR(10) NULL
-- HEADER ROW
--INSERT @TEMPTAB VALUES('00','Biometric Measure','Risk Citeria','N','Percent Of Screened Population','Average Value')
--BMI
--declare @BMI int
--select @BMI = count(*)
---FROM [frdmrpt].[wt_rpt_pha_pw_HRADetail2] hra
---INNER JOIN [frdmrpt].[wt_rpt_pha_pw_Member] mems
---ON hra.UserID = mems.UserID
--WHERE hra.BMI is not null and hra.BMI != 0.0
declare @BMI_T1 int
select @BMI_T1 = count(*)
FROM [frdmrpt].wt_pha_T1T2_HRADetail2 hra
INNER JOIN [frdmrpt].wt_pha_T1T2_Member mems
ON hra.UserID = mems.UserID and hra.T1T2=mems.T1T2
WHERE hra.BMI is not null and hra.BMI <> 0.0 and mems.T1T2 = 'T1'
--SELECT @BMI_T1
declare @BMI_T2 int
select @BMI_T2 = count(*)
FROM [frdmrpt].wt_pha_T1T2_HRADetail2 hra
INNER JOIN [frdmrpt].wt_pha_T1T2_Member mems
ON hra.UserID = mems.UserID and hra.T1T2=mems.T1T2
WHERE hra.BMI is not null and hra.BMI <> 0.0 and mems.T1T2 = 'T2'
---SELECT @BMI_T2
declare @BMIavg_T1 float
select @BMIavg_T1 = cast(isnull(AVG(BMI),0.0) as decimal (5,1))
FROM [frdmrpt].wt_pha_T1T2_HRADetail2 hra
INNER JOIN [frdmrpt].wt_pha_T1T2_Member mems
ON hra.UserID = mems.UserID
WHERE hra.BMI is not null --and hra.BMI <> 0.0
and mems.T1T2 = 'T1'
--SELECT @BMIavg_T1

Similar Messages

  • Hashing of the password field using MD5 and then store in the XML

    Hi,
    I need to design a form with User ID and a Password field. When i extract the XML from the form i need to hash the password field using MD5 and then store it. Does anyone have some kind of experience in doint it. Can you please suggest some way to do it.
    Thanks,
    Sayoni.

    Hi,
    To hash password you can use function from http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_md5/ or try to find another implementation. Just call this function on some event like button click for example.
    Also I made some example. See attach.
    BR,
    Paul Butenko

  • Table maintanence - display more fields

    Hi everybody,
    I had a TABLE MAINTENANCE GENERATION  transaction for my ztable
    Now my problem is
    I want to display 5 more fields which are already in my ztable in my transaction(table maintenance generated)
    these fields must be editable I meant when I change them it must be edited in my ztable also...
    can anyone help me with how to do
    Thanks in advance.

    Hello Hema,
    First delete the created Tab. Main and recreate the Tab main.
    Then go the screen using SE80 and open through the Fun group.
    And change the attribute of the fields to output only. and make other fields of input.
    If useful reward,
    Vasanth

  • Joining two tables having no common fields using one select query

    Hi Experts,
    How to join two tables which are NOT having any field in common using only one select query?
    Your help will be appreciated.
    Thank you.

    Identify a third table (or more tables) with common fields with your two tables, or change your question either removing JOIN or removing NO COMMON FIELDS, else you wont get many responses and will be left alone in outer space, as suggested by Thomas.
    If you acturally require what you written, better execute two select and merge the two internal tables merging every record from first table with every record of second table, til no more memory is available.
    Regards,
    Raymond

  • Error while linking user defined table to user defined field using vb6.0

    Hi,
    I am creating a userdefined field on a SAPB1 table(PDN1) using vb 6.0
    I am trying to link this field to a user defined table.
    When i do that i get the following error:
    "The field 'Related table' should consist of 8 alphanumeric chracters with no valid or default values"
    When i try to do the same thing from SAPB1(not using code) there is no such problem.
    My vb code is as follows:
    Set oUserFieldsMD = oCmp.GetBusinessObject(oUserFields)
    oUserFieldsMD.TableName = "PDN1"
    oUserFieldsMD.Name = "OB_Locn"
    oUserFieldsMD.Description = "WH Location"
    oUserFieldsMD.Type = db_Alpha
    oUserFieldsMD.EditSize = 30
    lRetCode = oUserFieldsMD.Add
    If lRetCode <> 0 Then
        oCmp.GetLastError lErrCode, sErrMsg
        MsgBox sErrMsg
        GoTo Err_
    End If
    If Not oUserFieldsMD.GetByKey("PDN1", 0) Then
        MsgBox "Error"
        GoTo Err_
    End If
    oUserFieldsMD.LinkedTable = "OB_TEST"
    lRetCode = oUserFieldsMD.Update
    Your help will be much appreciated.
    Thanks.

    Great Sébastien!
    Looks like we could not survive here one day without your contribution
    Best regards,
    Frank
    PS: For readers of this thread who don't understand why
    EditSize
    must be "8":
    This is the size of the
    Code
    field in the user-defined table to which the new field OB_Locn (in the DB it will be U_OB_Locn) is linked to...
    So, it should be preferrably of the same size.

  • How to use a table name in the select statement using a variable?

    Hi Everybody,
                       I got a internal table which has a field or a variable that gets me some tables names. Now I need to retrieve the data from all these tables in that field dynamically at runtime. So could you suggest me a way out to use the select query which uses this variable as a table ?
    Regards,
    Mallik.

    Hi all,
    Actually i need some more clarification. How to use the same select statement, if i've to use the tabname in the where clause too?
    for ex : select * from (tab_name) where....?
    Can we do inner join on such select statements? If so how?
    Thanks & Regards,
    Mallik.

  • How to add one more field to an exist internal table

    hi abapers
    i am a very new abap programmer and just started learning it.
    i want to know How to add one more field to an exist internal table.
    lemme me put my question in a very simple way.
    i have a internal table having fields f1,f2,f3 and which also that internal also contains some data.
    now i want to add two more fields (mm & nn) to that internal table now.
    how can i do that.
    and i wanna know the websites names where i can find some brain teasing questions in abap programming.
    eagerly waiting for ur reply
    regards,
    Maqsood A Khan

    Hi, MAQSOOD.
    You can insert more fields in your internal table like this.
    refer this code snippet.
    DATA : BEGIN OF tbl_itab OCCURS 0.
            INCLUDE STRUCTURE zsdtc009.
    DATA :  vkorg   LIKE vbak-vkorg,  "inserted one
            vtweg   LIKE vbak-vtweg,  "inserted one
            vkbur   LIKE vbak-vkbur,  "inserted one
            vkgrp   LIKE vbak-vkgrp,  "inserted one
           END OF tbl_itab.
    you can also read the book "Teach yourself abap in 21 days"
    at http://cma.zdnet.com/book/abap/
    but that book is just about basic concept of abap and report program.
    it doesn't give a lecture for on-line program.
    you can get pdf version books(about abap, sap...things) from sap.
    http://help.sap.com/printdocu/core/Print46c/en/Data/htm/english.htm
    I wish I could help you.
    Regards
    Kyung Woo.

  • How to accomodate more than 255 characters in character field

    HI All
    i need to accomodate more than 255 characters in character field. How can i do that ?
    thanks in advance!!!

    Hi,
    You can try the following things:
    1. Use a datatype STRING and check it will work.
    2. In se11 transaction goto datatype and search for char* in data elements.
    You will find predefined data types ,you can make use of it.
    For eg. char2000,char3000,char4000 etc.
    Hope this will help.
    Regards,
    Nitin.

  • Search Help on Table Control - Fill more than one field in the table?

    Hey everyone,
    I have built a screen with a Table Control on it... the fields of the table control are linked to an internal table...  The internal table has the line type of a structure I've defined in the data dictionary.  Within that structure in the data dictionary, I've linked some fields to search helps (For example, a MATNR and CUSTOMER search help)...  I've defined in the structure definition which fields from the search help are to be returned to which fields in the structure.
    The problem is, even though I have the search help set to export both the customer number and location when using the search help on the customer field, it still does not fill the location field within the table.  Is this a limitation of using search helps within table controls?
    I'm also finding that by defining the search help through the structure, instead of directly within the screen, the search help round button does not show up on the field, yet I can still press F4 to bring up the search help.  Is there a reason why it's not showing the search help clickable button even though it works fine using F4?
    For doing search helps in Table Controls, is it better to just build the search help, attach it directly to the field in the table, and then after the user picks the single field, use the PAI to run a select and fill the rest of the fields required?
    Thanks,
    Dallas

    Hi Dallas,
    (1)
    What  i understood is that you added a search help by defining it in the internal table type for a field customer number..in the search help you have 2 fields customer number and location...user press the search help ..then you need to fill 2 different fields or 1 field?
    if you need to fill the customer location or location (only one) then you need to set the "import" in the search help for whichever is required.....
    if you need to fill 2 or more different fields..then you can use the technique you have mentioned last , to do a select in PAI and fill the fields....but this you can use if the combination for the fields is unique...eg: u have customer number and location..if customer X can be mapped to location X and location Y..when a select statement is done there are 2 options..so in such cases it is better to leave the option to the user otherwise if there is a clear mapping like customer X can be mapped only to location X then you can use the select..
    (2)
    usually when you define it as a type in the internal table the icon doesn't show up..but you can do alternative like mentioned..go to the table,find the search help for the required field if present or create a new one if required and place the search help mentioned in the screen itself..so as to see the icon...sometimes users are adamant that they need the search help icon to be seen..so it depends on if your user
    (3)
    as in the example of customer number and location mentioned we can provide them different search helps and do the needful processing in PAI to fill the fields
    Table controls may be used for different purposes and requirements....even a checkbox,push button can be placed as a field in table control and used,but yes most of the time requirements are like what is mentioned in your case...
    Regards
    Byju

  • Need to insert into a table 1 of the fields (CLOB)with more than 4000 chars

    Dear Gurus,
    As far I understood, I need to write a function which get as parameter the large text and using bind variables I can return a CLOB containing more than 4000 chars. I tried all I can do and feel I want to died. Please, can I get specified help in this issue?
    I APPRICIATE YOUR HELP, MARCELO.

    *** Duplicate Post ***
    Please, Marcelo, use the forum properly. Pick a single group and post there.
    Thank you.

  • Weblogic Conversational WebService Database table migtration to 8 in WLS10

    Does the Weblogic Conversational WebService Database table WLS 8.1 still exist in Weblogic 10 (for migration purpose) (in WLS 8.1, the table name was mentioned in the wlw-manifest.xml) ?
    If not what table does the WebService use to persiste its state ?
    The WLI upgrade documentation mentioned that the wlw-manifest.xml migrate from the META-INF to the WEB-INF, does it still the same for Weblogic ? (no recommandationon this subject)
    Does it still a test console for conversational WebService ?

    Robert Jung wrote:
    Hi all,
    like many others in the web I'm having problems deploying CMP Beans on BEA. I'm using Weblogic 8.1 and
    get the following error message:
    "[EJB:011076]Unable to deploy the EJB 'B' because the database table 'b' is not accessible.Please ensure that this table exists and is accessible."
    >
    After a lot of research I understand the problem now. Weblogic is checking the cmp-fieldsat deployment time using something like "SELECT xx1, xx2, xxx3 FROM ttt1 WHERE 1 = 0".
    Some databases have no problem with such a select. My Solid database unfortunately does
    a full table scan on it. Having only some rows in the table b there is no problem at all,
    but I have more than 500.000 entries. :-(
    >
    My question: Is there a workaround? Can I somewhere specify the SQL - command for checkingmapped cmp-fields? Or can I disable the check somehow?
    I think it is a very annoying problem, many users out there have.Hi. All commercial quality DBMSes I know, are smart enough to evaluate constant search
    criteria, and not to access all the rows if it's a-priori known that no rows will
    qualify. I would ask 'Solid' for a fix.
    However, you can generate our EJBs with the option of retaining the generated
    JDBC code, which you could alter and recompile for your use. You might be able to
    substitute some DatabaseMetaData call to getTableColumns() to get the same info...
    Joe
    Thanx in advance
    Robert

  • Multi-record / spread table...moveable fields in designer generated form

    Good morning all;
    I hope you are doing good...
    Imagine a multi-record block layout with it's overflow property set to spread-table to accomodate 10 varchar2(25) fields. Now, of the hundreds of users working with this generated form, not one of them wants to see the fields in the same order on the screen.
    What i would like to do is generate the form from designer so that a user could 'drag'n drop' let say, field #10 to the field #2 spot on the screen. Something like windows explorer where you can move the 'Size' column around so it is viewable without having to use the spread-table bar at the bottom of the screen...
    Any idea on how to generate this form from designer?
    Thank you and wish me luck!

    I don't know a solution, but I think a solution could be easier found if it was a read-only block. You did not specify that. Then maybe you could dynamically change the query behind the block.
    Good luck, Paul.

  • No data in Active table of DSO for fields populated by End Routine

    Hi,
    I have a Standard DSO where we are populating few fields by using End Routine.
    Last week we added 5 more fields to DSO and wrote a logic in End ROutine to populate the DSO. These new fields dont have any mapping and these are just populated by end routine only.
    When I loaded the data from Data Source TO DSO, Data is loaded correctly into NEW DATA Table of DSO for all the fields. I could see correct data as per the logic in NEW Table including old and new fields.
    However, when I activate the DSO, I could not find the data for new fields which I added last week. Remaining fields are getting data as per the logic. Only these five fields are not having any data.
    Can you please let me know if any one had similar issue. I was under impression that all the data in the new table will go to Active table when we activate the DSO.
    Your inputs are highly appreciated.
    Thanks
    Krishna

    What version of BW are you using?  When editing your end-routine, a pop-up should display saying which fields you want populated/transferred from the end routine.  This pop-up will not display if you are using a lower version of BW 7.x.  To get around this, make sure that your newly added fields have a transformation rule type set to constant.  This will make sure that the fields get populated when transferring from new to active tables.

  • How to add 2 more field to the  Header of FBL5N ALV report output

    Hi All,
    I have copied and made some modification to the standard transaction FBL5N and added some fields to the ALV report line Items but how to add fields to the header part i.e if you execute the transaction FBL5n, you will get the ALV report, in the header part customer no, company code then I need to add the 2 more fields. can any one tell me that which structure or where I need to add these fields to be appear in ALV output screen.
    Thanks in advance.
    Swapna.

    Hi Mohamed,
    If you copied Z-FM successfully, then you have to go to subroutine TOP_OF_PAGE to add your field:
    *&      Form  TOP_OF_PAGE
    FORM top_of_page.
      DATA: b_suppress   LIKE boole-boole,
            opfi_text    LIKE eptext OCCURS 10 WITH HEADER LINE,
            n_color      TYPE i.
    *  IF     NOT it_items-bukrs IS INITIAL               "737295
    *     AND NOT it_items-konto IS INITIAL               "737295
    *     AND NOT it_items-koart IS INITIAL.              "737295
      gs_items = gt_alv.
    *  ENDIF.                                             "737295
    * skip first call at top of page:
      IF NOT gd_first_top IS INITIAL.
        CLEAR gd_first_top.
        EXIT.
      ENDIF.
      IF x_grid = c_x OR x_inet = c_x.                          "1012201
        PERFORM grid_top_of_page.
        EXIT.
      ENDIF.
    *... open FI: get header text.
    * first fill some RFXPO fields for general info:
      CLEAR: s_rfxpo, wa_kna1, wa_lfa1, wa_ska1.
      s_rfxpo-bukrs = gs_items-bukrs.
      s_rfxpo-kkber = gs_items-kkber.
      s_rfxpo-koart = gs_items-koart.
      s_rfxpo-konto = gs_items-konto.
      s_rfxpo-vrbez = gs_variant-variant.
      s_rfxpo-waers = gs_items-waers.
    * update master record:
      PERFORM fill_master_rec  USING gs_items-koart
                                     gs_items-konto
                                     gs_items-bukrs. " note 698396
      CALL FUNCTION 'OPEN_FI_PERFORM_00001640_E'
        EXPORTING
          i_rfxpo             = s_rfxpo
          i_kna1              = wa_kna1
          i_lfa1              = wa_lfa1
          i_ska1              = wa_ska1
        IMPORTING
          e_suppress_standard = b_suppress
        TABLES
          t_lines             = opfi_text.
    *... display open FI text:
      IF x_konto_sort = 'X'.
        LOOP AT opfi_text.
          CASE opfi_text-color.
            WHEN 1.
              FORMAT COLOR 1.
            WHEN 2.
              FORMAT COLOR 2.
            WHEN 3.
              FORMAT COLOR 3.
            WHEN 4.
              FORMAT COLOR 4.
            WHEN 5.
              FORMAT COLOR 5.
            WHEN 6.
              FORMAT COLOR 6.
            WHEN 7.
              FORMAT COLOR 7.
          ENDCASE.
          WRITE: / opfi_text-text.
        ENDLOOP.
        FORMAT RESET.
      ENDIF.
    *... display other header text:
      IF b_suppress NE 'X'.
        PERFORM display_custom_header.
        PERFORM display_ccard_lines.
      ENDIF.
    " Put your field somewhere...
    ENDFORM.                               " TOP_OF_PAGE
    Good luck,
    Thanks,

  • Need to add more Fields to "List" Tile of MSA Opportunity Search Tileset.

    Hi Experts !
    We are trying to add more fields to the "List" Tile on the Opportunity Search Tileset to view additional information on the search result screen.Ex: Company Name, Product Description, Person Responsible & Channel Partner on Opportunity transaction should be displayed on the Search result screen.
    So far, with the help of Anchor modeling we tried adding the Opportunity BP (BOOPPBusinessPartner) Segment and (BOOPPProduct) Segment to the BOOpportunity Parent segment in the Opportunity_Write Bdoc.And, we added fields from BP & Product segment to the List tile by drag & drop.
    Upon Generating the changes, the system did NOT populate the data for the new fields.
    Please advise us where we are going wrong.
    Thanks & Regards,
    Jagan.

    Hi,
    the way you tried to add some more fields in a list tile is not working.
    In lists the data is not retrieved from Business objects/collections but from record sets which are fetched from the main segment of the underlying query BDoc (I guess sth like OPP_blabla_QUERY).
    Therefore what you could do is to enhance this query BDoc and add these tables by joining them to the opportunity header table. In this case you also need to specify exactly these segment field names in the property of the new list column fields.
    Much faster (but a little bit dirty) would be to use the row loaded2 event where you can calculate the values you want to display. In this case the controls would have to be unbound.
    The second version would cost a little bit more performance, but this depends from the data volume.
    Regards,
    Wolfhard

Maybe you are looking for

  • Invalid serial number for Acrobat 9 Pro

    I have a new computer that has Windows 8 operating system and am trying to install Adobe Acrobat 9 Pro that I purchased a couple of years ago. When I enter the serial number it says it's invalid - does anyone know why this might be happening?

  • ABAP program to resubmit itself with temp variant

    Hi there, I want a program to be able to re-submit itself in the background. I can do this, but if the user does not use a variant, how do I submit the program with the user-defined selections? This program may be run often and I don't want to create

  • Framework purchase order

    Hi experts, What is meant by "Framework Purchase Order"? What are the types of contract maintained in MM module? Also, what is the difference in creating a purchase order for service contract and other contracts using BAPI? Regards, Shanthi

  • Best way to pass large amounts of data to subroutines?

    I'm writing a program with a large amount of data, around 900 variables.  What is the best way for me to pass parts of this data to different subroutines?  I have a main loop on a PXI RT Controller that is controlling hydraulic cylinders and the loop

  • 7.0 Activation Issue

    I am trying to install my Acrobat writer 7.0 on my new computer. When trying to activate I get a message saying the activation server is not avaliable. What should I do?