specify yorn if field is populated in other relationsal table

Posted on 2007-10-09
Last Modified: 2012-06-27

i have two tables

workorder and asset

in my asset table I have data like so

asset    contract
car1      waranty1
car1      waranty2
car2      null
car3      repair

in my workorder table i have three fields

workid     asset  description
1             car1    broken
2             car2    inop

how can i add a field into my query to state in YORN form if the contract field is present
to that specific asset in my asset table like so

workid     asset  description    contracts exist?
1               car1    broken              Y
2               car2    inop                  N

All help will do

Question by:rutgermons
    LVL 142

    Expert Comment

    by:Guy Hengel [angelIII / a3]
    select a.*, case when w.workid is null then 'N' else 'Y' end contract_exists
    from asset a
    left join workorder w
      on w.asset = a.asset
    LVL 14

    Accepted Solution

    select wo.workid, wo.asset, wo.description,
        decode(max(a.contract), null, 'N', 'Y')
      from workorder wo
        inner join asset a on wo.asset = a.asset
      group by wo.workid, wo.asset, wo.description

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
    How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
    This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
    Via a live example, show how to setup several different housekeeping processes for a SQL Server.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now