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

Please, help me with SQL 1

Status
Not open for further replies.

Ladyazh

Programmer
Sep 18, 2006
431
US
Please, help me to write following:

name contact id
AAA e 12
AAA b 12
NULL e 11
BBB b 11

So if contract is e then name.
If contract is e and name is null then name then contract b and name.

Thanks.

P.S. I always want cotract e but if not avail then b and name under b.
 
Code:
SELECT ISNULL(ECont.Name, BContr.Name) AS Name
FROM (SELECT Name FROM YourTable WHERE contact = 'e') ECont
FULL JOIN (SELECT Name FROM YourTable WHERE contact = 'b') BConr ON ECont.Id = BCont.Id

not tested

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
MVP VFP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top