Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
Deep writes "Sir/MadamI want to pick only one email-id per domain.for e.g Table -> Subscribe Field -> emailData : abc@hotmail.com xyz@hotmail.com abc@yahoo.com xyz@yahoo.comoutput : abc@hotmail.com abc@yahoo.complease send the query"
nr
SQLTeam MVY
12543 Posts
Posted - 2004-11-22 : 07:31:40
something likeselect distinct data from Subscribe t1where data = (select top 1 t2.data from subscribe t2 where right(t1.data, charindex('@',reverse(t1.data))-1) = right(t2.data, charindex('@',reverse(t2.data))-1))==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy.
spirit1
Cybernetic Yak Master
11752 Posts
Posted - 2004-11-22 : 07:33:25
or
declare @Subscribe table (email varchar(50))insert into @Subscribeselect 'abc@hotmail.com' union allselect 'xyz@hotmail.com' union allselect 'abc@yahoo.com' union allselect 'xyz@yahoo.com'select min(email)from @Subscribe group by substring(email, charindex('@', email), len(email))