|
Posted by Faye on 11/05/07 15:49
Hi,
The following SELECT statement works fine and returns what I need as
one of the columns in my query. I have to create more than 10 of the
selection statements like this and then UNION them into a final query.
What I want to do is to have an example to show me how create a
function to pass the column name and the table name to create the
query.
SELECT LN_NR, ROUND(CAST(amountTotal AS DECIMAL(7, 2)) /
positionTotal, 0) AS AverageYearsinPresentPosition
FROM (SELECT SURV_YY_DT, LN_NR, SUM(TOT_PSTN_OFFCR_NR) AS
positionTotal, SUM(TOT_YY_PSTN_NR) AS amountTotal
FROM (SELECT TOP 100 PERCENT
SURV_YY_DT, LN_NR, TOT_PSTN_OFFCR_NR, TOT_YY_PSTN_NR
FROM
dbo.FLT_OFFCR_SLRY_SURV_DTL AS FLT_OFFCR_SLRY_SURV_DTL_1
WHERE
(TOT_YY_PSTN_NR > 0)
ORDER BY LN_NR) AS
presentYears_1
GROUP BY SURV_YY_DT, LN_NR) AS presentYears
WHERE (SURV_YY_DT = '2007')
Thank you.
Faye Larson
[Back to original message]
|