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)
 Return a list of prefixes

Author  Topic 

rkruis
Starting Member

28 Posts

Posted - 2011-10-11 : 13:53:39
I have a table with a few fields. One of the fields (Abstract) is a 255 char with example data shown below. Each of the records is prefixed with a string and then a dash.

I would like to return all unique prefixes before the dash. Is there a way to do this?

Data
IDX Abstract
121 ACC - a string of text
122 ACC - a string of text
123 ABAC - a string of text
124 DEEF - a string of text
125 ABBDE - a string of text
126 ACC - a string of text
127 ABBDE - a string of text


Return (Just the prefixes not duplicated)
ABAC
DEEF
ABBDE
ACC

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-11 : 14:19:24
yup. do like

SELECT DISTINCT LEFT(Abstract + ' - ',CHARINDEX(' - ',Abstract + ' - ')-1)
FROM Data



------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

rkruis
Starting Member

28 Posts

Posted - 2011-10-11 : 17:20:13
Thank you very much. I will try this tonight :)
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-12 : 01:25:18
welcome
let me know how you got on

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -