Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Can you join on an alias?

$
0
0

Hi,

Is it possible to join on an alias (month):

SELECT 
pehPErcontrol,case left(substring(pehPErcontrol,5,len(pehPErcontrol)),2) when '01' then 'January' when '02' then 'Feburary' when '03' then 'March' when '04' then 'April' when '05' then 'May' when '06' then 'June' when '07' then 'July' when '08' then 'August' when '09' then 'September' when '10' then 'October' when '11' then 'November' when '12' then 'December' end as month,
rtrim(eepNameLast) + 
',  ' + rtrim(eepNameFirst) + 
' ' + coalesce(substring(eepNameMiddle,1,1) + '.', '') as Name, 
eepNameLast AS [Last Name],
IsNull(eepNameSuffix,'') AS [Suffix],
eepNameFirst AS [First Name],
IsNull(eepNameMiddle,'') AS [Middle Name],
pehCurAmt AS [Current Amount], 
pehCurHrs AS [Current Hours], 
pehCoID AS [Company ID], 
pehEEID AS [EE ID], 
pehEmpNo AS [Emp No], 
pehLocation AS [Location], 
pehJobCode AS [Job Code], 
pehOrgLvl1 AS [Org Level 1],    
pehOrgLvl2 AS [Org Level 2], 
pehOrgLvl3 AS [Org Level 3], 
pehOrgLvl4 AS [Org Level 4], 
pehPayGroup AS [Pay Group], 
pehProject AS [Project], 
pehShfShiftAmt AS [Shift Amount],
pehearncode AS [Earn Code]
FROM EmpPers JOIN pearhist  
ON pehEEID = eepEEID 
join  WSISQL4.DASHBOARD.DBO.[OVERTIME_BUDGET_2013] ON [orglevel] = pehOrgLvl2
inner join  WSISQL4.DASHBOARD.DBO.[OVERTIME_BUDGET_2013] on [month] = v.month


qeqw


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>