Thread: Using Distinct
View Single Post
 
Old November 29th, 2007, 01:25 AM
Jeff Moden Jeff Moden is offline
Friend of Wrox
Points: 1,536, Level: 15
Points: 1,536, Level: 15 Points: 1,536, Level: 15 Points: 1,536, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2006
Location: , MI, USA.
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
Default

Code:
 SELECT TEL, FIRSTNAME, LASTNAME, ADDRESS1, TOWN, COUNTY FROM [TABLENAME]
   INTO #MyHead
  WHERE 1 = 0

 INSERT INTO #MyHead (TEL)
 SELECT DISTINCT Tel
   FROM [TABLENAME]

 UPDATE #MyHead
    SET FirstName = t.FirstName,
        LastName  = t.LastName,
        Address1  = t.Address1,
        Town      = t.Town,
        Country   = t.Country
   FROM #MyHead mh,
        [TABLENAME] t
  WHERE mh.Tel = t.Tel

 SELECT * FROM #MyHead


--Jeff Moden