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
 General SQL Server Forums
 New to SQL Server Programming
 single unique character query

Author  Topic 

paseroto
Starting Member

1 Post

Posted - 2014-10-27 : 07:00:37
Hi Guys,
I have a huge database (20 columns and 56000 lines) and I need a query that can return each single unique character from all this database.
For example if character "a" appears at least one time in this database I need this query to show it to me.

Please Help,
Paseroto

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2014-10-27 : 08:51:37
that is not a huge database (actually it's quite small).

If I understand your problem, you could first build a query that takes in your 20 columns and outputs unique characters from each column then combines them to produce a unique set over the whole table. For example, say I have this table:


create table foo(a char(5), b char(5), c char(5)

-- find unique characters

select substring(a,1,1) chars
union
select substring(a,2,1)
union
select substring(a,3,1)
union
select substring(a,4,1)
union
select substring(a,5,1)
-- column b
union
select substring(b,1,1)
union
select substring(b,2,1)
union
select substring(b,3,1)
union
select substring(b,4,1)
union
select substring(b,5,1)
-- column c
union
select substring(c,1,1)
union
select substring(c,2,1)
union
select substring(c,3,1)
union
select substring(c,4,1)
union
select substring(c,5,1)


this should produce a result set where column 'chars' are unique

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2014-10-27 : 09:25:03
I think you are looking for something like this http://beyondrelational.com/modules/2/blogs/70/posts/10883/search-a-value-in-character-column-of-all-tables.aspx

Madhivanan

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

- Advertisement -