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
 Data Mining Suggestions?

Author  Topic 

larryg003
Starting Member

18 Posts

Posted - 2010-06-11 : 09:17:05
Hi guys, i just joined SQLteam.com and I am really impressed with the community.

Now on to my question:

I have 10 columns and 8,000,000 rows which have stock ticker names and exchange tickers-like the following:
[Column A]
AQR.L
GDY.LS
NBAE.LS
0023CA.S
FOR.L
AQR.KZ
...
...
How do I find the number of unique ticker names in my database and disregard the .L, .LS, .S, .L, .KZ endings (because I am looking for the unique tickers, not the exchange). I.E., I want
the values counted to be only AQR, GDY, NBAE, 0023CA, FOR or 5 values (I don't want AQR to be counted twice because it is listed on two separate exchanges).

Thank you so much,

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-06-11 : 09:25:52
The query can take a while...
select
left([Column A],charindex('.',[Column A])-1),
count(*) as cnt
from your_table
group by left([Column A],charindex('.',[Column A])-1)

Assuming that in every entry is a dot like shown in your sample data.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

larryg003
Starting Member

18 Posts

Posted - 2010-06-11 : 12:18:55
Thank you for your suggestion.

I tried the Query, but it did not seem to work.
It says that there is an error occurring near the word as. Kinda weird.
I am using SQL management studio and I forgot to mention that I also have Gaps in the Data, so some of the data may be like this:
[Column A]
ASD.L
(blank)
DJS.LS

Any suggestions?
Go to Top of Page

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2010-06-11 : 12:22:44
where col1 is not null
Go to Top of Page
   

- Advertisement -