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.
| Author |
Topic |
|
kamii47
Constraint Violating Yak Guru
353 Posts |
Posted - 2008-08-26 : 07:41:38
|
| I have Code Company CompanyCount ContactPerson702 Bistro Delifrance 1 NULL97 Delifrance 15 NULL98 Delifrance 15 NULL99 Delifrance 16 NULL99 Delifrance 15 NULL100 Delifrance 15 NULL100 Delifrance 15 testI need the following resultCode Company CompanyCount ContactPerson702 Bistro Delifrance 1 NULL97 Delifrance 15 NULLThat is if company delifrance is repeated then just get its first recordKamran ShahidSr. Software Engineer(MCSD.Net,MCPD.net)www.netprosys.com |
|
|
ranganath
Posting Yak Master
209 Posts |
Posted - 2008-08-26 : 07:51:05
|
| hi,try with thisDeclare @Temp Table (Code Int, Company varchar(100), CompanyCount Int, ContactPerson varchar(100))Insert into @TempSelect 702, 'Bistro Delifrance', 1, NULL Union AllSelect 97, 'Delifrance' ,15, NULL Union AllSelect 98, 'Delifrance', 15, NULL Union AllSelect 99, 'Delifrance' ,16, NULL Union AllSelect 99, 'Delifrance' ,15, NULL Union AllSelect 100, 'Delifrance' ,15, NULL Union AllSelect 100, 'Delifrance', 15, 'test'Select Code, Company, Companycount, ContactPerson From (Select Code, Company, Companycount, ContactPerson, ROW_NUMBER() OVER (PARTITION BY Company order by CompanyCount)AS 'Row'From @Temp )Awhere Row = 1 |
 |
|
|
sunil
Constraint Violating Yak Guru
282 Posts |
Posted - 2008-08-26 : 07:52:48
|
| Try thisSelect * FROM(SELECT CODE,COMPPANY,COMPANYCOUNT ,CONTACTPERSON, ROW_NUMBER() OVER(PARTITION BY COMPANY,Delifrance ORDER BY COMPANY )AS 'RID' FROM yourtable ) tbl WHERE RID=1 |
 |
|
|
kamii47
Constraint Violating Yak Guru
353 Posts |
Posted - 2008-08-26 : 08:15:48
|
| Thanks sunil.It workedKamran ShahidSr. Software Engineer(MCSD.Net,MCPD.net)www.netprosys.com |
 |
|
|
sunil
Constraint Violating Yak Guru
282 Posts |
Posted - 2008-08-26 : 08:22:48
|
| You are welcome. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-08-26 : 08:27:58
|
quote: Originally posted by sunil Try thisSelect * FROM(SELECT CODE,COMPPANY,COMPANYCOUNT ,CONTACTPERSON, ROW_NUMBER() OVER(PARTITION BY COMPANY,Delifrance ORDER BY COMPANY )AS 'RID' FROM yourtable ) tbl WHERE RID=1
there's no field called delifrance in op's sample. thats just a value existing in company field |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
|
|
|
|
|