jadams0173
Technical User
- Feb 18, 2005
- 1,210
I need to reference an aliased column from my select list in another part of my select list.
I have it currently where I just repeat the way I got the aliased column but it's hard to ready and looks bad to me. If this "look" is ok then I'll go with it. Just want to try to be as friendly as I can be to me six months from now and others if they try to read the code as to what I've done.
I think I needed the aliased as a derived table but i'm not exactly sure how to do it.
I have it currently where I just repeat the way I got the aliased column but it's hard to ready and looks bad to me. If this "look" is ok then I'll go with it. Just want to try to be as friendly as I can be to me six months from now and others if they try to read the code as to what I've done.
I think I needed the aliased as a derived table but i'm not exactly sure how to do it.
Code:
SELECT
DATEDIFF(DAY,A.START_DATE, A.SCHED_DATE)as LEAD_TIME,
A.COST_FMLY,
CASE
WHEN A.MIN_RATE =0
THEN 0
ELSE
CONVERT(DECIMAL(5,5),1/CONVERT(FLOAT,A.MIN_RATE))
END AS BDS_UNIT_HR ,
rtrim(A.[Description])"PROCESS_DEF",
CASE A.PASS
WHEN 1 THEN COALESCE(C.PRIMLINE,'N-A')
WHEN 2 THEN COALESCE(B.PRIMLINE,'N-A')
ELSE 'N-A'
END AS OTHER_SIDE,
[BLUE]COALESCE(E.LINEID, CASE
A.MOTYPE
WHEN 'AI' THEN 7
WHEN 'HLA' THEN 9
WHEN 'PTH' THEN 8
ELSE 10
END) AS PRIM_LINE [/BLUE],
COALESCE(D.SCHEDULED_LINE,[BLUE]COALESCE(E.LINEID, CASE
A.MOTYPE
WHEN 'AI' THEN 7
WHEN 'HLA' THEN 9
WHEN 'PTH' THEN 8
ELSE 10
END)) AS SCHEDULED_TO[/BLUE]
from vw_MyPrimaryLine A
LEFT JOIN (SELECT MO_NUMBER, ITEM, TB,PASS, PRIMLINE
FROM vw_MyPrimaryLine
WHERE PASS = 1 ) B
ON A.MO_NUMBER = B.MO_NUMBER
LEFT JOIN (SELECT MO_NUMBER, ITEM, TB, PASS,PRIMLINE
FROM vw_MyPrimaryLine
WHERE PASS = 2) C
ON A.MO_NUMBER = B.MO_NUMBER
AND C.MO_NUMBER = B.MO_NUMBER
LEFT JOIN SCHEDULE_DATA D
ON D.MO = A.MO_NUMBER
LEFT JOIN LINE_NAMES E
ON A.PRIMLINE = E.LINEDESC