Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 join syntax

Author  Topic 

PGG123
Yak Posting Veteran

55 Posts

Posted - 2010-06-07 : 16:18:02
I haven't been doing SQL programming in a while, so I don't remember a lot of syntax.

I have this query. This query will display results only for people that have been issued cards. How do I rewrite this so that even those without cards will still be returned? Also is the date syntax correct?

select a.activationdate_dt, a.lastname_tx, a.firstname_tx, a.middleinitial_tx, a.badge_tx, b.cardcode_tx, c.customfieldvalue_tx as employeeID
from table1.dbo.idholders a
inner join table2.dbo.cards_t b on a.ssidholder = b.cardholderid_in
inner join table2.dbo.chcustomfieldmap_t c on
b.cardholderid_in = c.cardholderid_in
where a.creationdate_dt >= '03/01/2010' --March 1, 2010
and c.customfieldid_tx = '123456'

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-06-07 : 16:22:00
Use an OUTER JOIN, typically LEFT JOIN, for the table with the cards.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -