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 2005 Forums
 Transact-SQL (2005)
 Need to Distinct CharacterParticular column result

Author  Topic 

urzsuresh
Starting Member

30 Posts

Posted - 2011-01-05 : 01:52:28
Hello,
I need to bring the distinct result in third column
Below one is my sample table


Declare @t table
(
Id int,
name varchar(50),
Actions varchar(50),
Active int
)

Insert into @t
Select 1,'One','aabccdddee',1 Union all
Select 2,'Two','bbccce',1 Union all
Select 3,'Three','fdeg',1 Union all
select 4,'Four','ggeefff',1

Select * from @t


My Required Output is


1 One abcde 1
2 Two bce 1
3 Three fdeg 1
4 Four gef 1


can any one guide me through sample code

Suri

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-01-05 : 01:57:37
Easiest way is to redesign so that actions is a separate table. You have a column which does not hold a single attribute here and is probably always going to cause trouble.

If you are forced to go with this then maybe create the activity table by splitting up the sring into characters then select the distinct values and reform the string.

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-01-05 : 03:42:37
See if this helps
http://beyondrelational.com/blogs/madhivanan/archive/2007/12/29/remove-duplicate-characters-from-a-string.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -