We help IT Professionals succeed at work.
Get Started

Return SQL Result with another field if it is not null

tsmit877
tsmit877 asked
on
294 Views
Last Modified: 2012-05-09
The following query produces the correct result only if my customer has a billing address that is separate from their main address.  I would like the query to return Pat.Address1 if there aren't any records where PatAdd.UseForBilling = 1
SELECT ARPayment.amount,ISNULL(LastName, '') + ', ' + ISNULL(FirstName, '') AS PatientName,
ISNULL(PatAdd.Address1, '') + ', ' + ISNULL(PatAdd.Address2, '') AS AddLine1,
ISNULL(PatAdd.City, '') + ', ' + ISNULL(PatAdd.Prov, '') + ', ' + ISNULL(PatAdd.Postal, '')AS AddLine2,
ARPayment.[Date] AS PaymentDate, PatAdd.city, PatAdd.Prov, PatAdd.Postal
FROM ARPayment
INNER JOIN AR ON (ARPayment.ARID = AR.ID)
INNER JOIN Pat ON (AR.BillToPatID = Pat.ID)
INNER JOIN PatAdd ON (Pat.ID = PatAdd.PatID)
WHERE (ARPayment.[Date] >= '2009-01-01 00:00:00')
  AND (ARPayment.[Date] <  '2010-01-01 00:00:00')
  AND (Type = 0)
  AND (Pat.ID IN (26928)and PatAdd.UseForBilling = 1)

Open in new window

Comment
Watch Question
Senior Database Architect
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 1 Answer and 9 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE