Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

syntax issues with if else stmt 1

Status
Not open for further replies.

thminer

Technical User
Joined
Oct 11, 2005
Messages
16
Location
US
hey all
having some trouble with this if else. getting errors like "error 209 - ambiguous column name emEmployee" this is because column emEmployee is in all of the joined tables. thanks for the help.

IF EXISTS (Select * From tblbonus WHERE emSelect1 = 'Salary')
Begin
Select tblbonus.emEmployee, (directhours - 0) % ((weeksworked * 40) - vacationused) AS productivity
FROM tblbonus INNER Join tbldirecthours on (emEmployee = ldEmployee) Inner join tblweeksworked on (ldEmployee = emEmployee) Inner Join tblvacationused on (emEmployee = ldEmployee)
END
ELSE
BEGIN
SELECT tbldirecthours.ldEmployee, directhours / paidhours as productivity FROM tbldirecthours RIGHT join tblpaidhours on (ldEmployee = ldEmployee)
GROUP BY ldEmployee, directhours, paidhours
END
 
alias the tables and use the alias
example

Select t.emEmployee, (directhours - 0) % ((weeksworked * 40) - vacationused) AS productivity
FROM tblbonus t INNER Join tbldirecthours td on (t.emEmployee = td.ldEmployee) Inner join tblweeksworked tww on (td.ldEmployee = tww.emEmployee) Inner Join tblvacationused tvu on (tvu.emEmployee = td.ldEmployee)





Denis The SQL Menace
SQL blog:
Personal Blog:
 
thanks Denis. aliases on the tables worked great.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top