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 2000 Forums
 Transact-SQL (2000)
 Distinct characters in a field

Author  Topic 

mdhingra01
Posting Yak Master

179 Posts

Posted - 2005-01-12 : 14:13:36
Is there a way to query a field to determine the unique charcters in that
given field.

For example:
COLUMN1
apple
bat
car

The query should return
a
p
l
e
b
t
c
r

Thanks

mdhingra01
Posting Yak Master

179 Posts

Posted - 2005-01-12 : 14:40:34
I found this example works for what I am doing. Feel free to replace the sysobjects table with aonther if you need more than 135 in your numbers table.

use northwind
go

create table t (colA varchar(25))

insert into t values('apple')
insert into t values('bat')
insert into t values('car')

select top 25
identity(int, 1, 1) as number
into
number
from
sysobjects

select distinct
substring(t.colA, number, 1)
from
t cross join number as n
where
substring(t.colA, number, 1) > ''

drop table t, number
go
Go to Top of Page
   

- Advertisement -