Click here to Skip to main content
15,886,664 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how do i write a condition/statement that gets me the results seen in final table below? i have 2 tables, that have similar column, but in the final table i need to display the appropriate Description depending on the code and EDLType/codetype/DLType.

can someone help me please.

Final table:
comp    EDLType    EDLCODE    Eployee#    Desc
102      D         1          1000        Portion
102      D         2          1000        salary
102      D         3          1000        A.Tax
102      D         100        1000        Support
102      E         4          1000        T.time
102      E         1          1000        RTime
102      E         2          1000        OT
102      L         201        1000        E.Portion
102      L         200        1000        C.Portion


table 1:
Comp    ECode    Desc         codetype   
102      1       RTime        E   
102      2       OT           E   
102      3       DT           E   
102      4       T.time       E   
102      5       autopay      E   


table 2:
comp    DLCode    Desc           DLType   
102      1        Portion        D   
102      2        salary         D   
102      3        A.Tax          D   
102      4        B.Tax          D   
102      5        C.Tax          L   
102      200      C.Portion      L   
102      201      E.Portion      L   
102      100      Support        D   
Posted

You can achieve this by joining tables together using left join (or inner join, depending on your data and needs). Your sample above appears to be missing some information (such as where the Employee Number is coming from), but the general structure you need is like this:

SQL
select FIELD1, FIELD2 from table1
left join table2 on table1.DLCode = table2.EDLCode
 
Share this answer
 
i have done the left outer join, but i am getting the wrong desc. if i display both desc fields on my report, for certain edlcodes i am getting 2 desc. one from table 1 and the other from table 2.

the emp # is coming form another table. i didn't think it was needed for my question, sorry about that.

is there any other way a achieve what i want? for example in a if/loop statement?
 
Share this answer
 
Comments
_Damian S_ 19-Nov-13 0:04am    
My solution above wasn't to be taken literally, it was the way to go about it with the correct tables. Clearly you need to list all tables and their fields that appear in the result set, otherwise we can only give our best guess rather than an actual solution. Post the full set of tables that the fields in the result set come from.
please see below, all joined with left outer join.
primary table is PREA,
prea.prco to [all_tables].prco
prea.employee to prel.employee
prea.edlcode to prdl.dlcode
prea.edltype to prdl.dltype
prea.edlcode to prec.earncode

SQL
SELECT [PRCo]
      ,[EarnCode]
      ,[Description]
  FROM [bPREC]


SELECT [PRCo]
      ,[DLCode]
      ,[Description]
      ,[DLType]
  FROM [bPRDL]

SELECT [PRCo]
      ,[Employee]
      ,[EDLType]
      ,[EDLCode]
  FROM [bPREA]

SELECT [PRCo]
      ,[Employee]
      ,[LeaveCode]
  FROM [bPREL]



hope the above helps
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900