Creating a table for data that does not exist somewhere else

Answered Creating a table for data that does not exist somewhere else

  • Tuesday, January 29, 2013 9:47 PM
     
     

    Need to insert into a Temp Table any EE that has a DEN Dedtype DedCode but only if they do not have a MED Dedtype DedCode.  How can this be done?

    select x,x,x,x into tmp_table

    from Deductions Join DedType on Dedcode =DDedCode

    where DedType='Den' and DStatus ='A' and

    Not Exist (select * from Deductions join Dedtype on Dedcode=DDedCode where dedtype<>'Med' and eedbenstatus ='A')

All Replies

  • Tuesday, January 29, 2013 10:02 PM
     
     Answered Has Code

    Not clear about what you are asking for here. But try:

    Select x,x,x,x into tmp_table
    
    from Deductions D Join DedType DT on D.Dedcode =DT.DDedCode
    
    where D.DedType='Den' and D.DStatus ='A' and
    
    Not Exist (select TOP 1 1 from Deductions join Dedtype on Dedcode=DDedCode where dedtype='Med' and eedbenstatus ='A'
    				AND DedCode = D.DedCode)

    Also, I have aliased the tables just randomly, as you have not provided which column bleongs to which table. So Some sample data would help.


    Please mark as answer if this answers your question. Please mark as helpful if you found this post helpful.