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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Issue setting flag to Y or N based on outcome

Status
Not open for further replies.
Mar 1, 2001
37
US
I have a query that is returning information from a table like...

Select LastName, FirstName, HasDriversLicenseFlag from Borrower

I need to look in the DriversLicense Table to determine if the borrower has one or not. If they do, display "Y" else Display "N" for the HasDriversLicenseFlag.

Any idea how I can achieve this?
 
What is the column type of the HasDriversLicenseFlag column? Is it a bit?
 
The HasDriversLicenseFlag is a column, it is just the Column name I want to display for the user.
 
I'm thinking I'll have to do some sort of Left Outer Join like...

Select LastName, FirstName, HasDriversLicense
From Borrower b Left Outer Join
DriversLicense dl on b.BorrowerTrID = dl.BorrowerTrID

I just don't know how to display a Y if they have an entry in the DriversLicense table or a N if they do not have an entry in the table. Hope that clarifies.
 
You can try this, I have not tested it though:
Code:
Select LastName, FirstName, 
HasDriversLicense = 
  CASE 
    WHEN Count(dl.*) > 0
       THEN 'Y'
    WHEN Count(dl.*) = 0
       THEN 'N'
  END
From Borrower b Left Outer Join
  DriversLicense dl on b.BorrowerTrID = dl.BorrowerTrID
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top