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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 join on 2 fields

Author  Topic 

rajani
Constraint Violating Yak Guru

367 Posts

Posted - 2006-06-11 : 19:57:59
Hi friends
i've 2 tables (master- child) and (town- parent).
the child table has 2 fields(atown and town) that r linked to parent table.

select um.TOWN,um.ATOWN,ut.CITY,ut.COUNTRY,
'', um.BLDGBOX, um.STREETNUM, um.STREETNAME, ut.NAME, ut.CITY, ut.STATE, ut.POSTCODE, ut.COUNTRY AS [Full Address (multi-line)]
FROM dbo.u_master AS um
LEFT OUTER JOIN dbo.u_town AS ut ON
um.ATOWN = ut.TOWNID AND um.TOWN = ut.TOWNID

problem here is the columns city and country always return NULLS !!
if both fields (atown,town) filled in then i get to see city and town.
how can i change abv query so that
if town field not null then i want to see details of "town",
if atown field not null and town is null then i want to see details of that "atown",
if both are not null then i need to see details of "town"
Thanks for ur help


Cheers

rajani
Constraint Violating Yak Guru

367 Posts

Posted - 2006-06-11 : 19:59:26
is this as simple as changed "AND" to "OR" ?
i mean from
um.ATOWN = ut.TOWNID AND um.TOWN = ut.TOWNID
to
um.ATOWN = ut.TOWNID OR um.TOWN = ut.TOWNID

Cheers
Go to Top of Page
   

- Advertisement -