Sandesh Meda

Blogging on .NET, SQL Server and Sharepoint Technologies

<November 2008>
SuMoTuWeThFrSa
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456


Navigation

Subscriptions



Monday, February 27, 2006 - Posts

Splitting a string in SQL Server 2000

I was "select"ing from a datasource that stored data in the format "Lastname, Firstname" ex: "Smith, John". The fastest way to do this is to tokenize the string with the "," delimiter. However, I realized there is no "split" function in SQL Server.

In SQL Server 2000, a workaround would be to use the SUBSTRING() along with the CHARINDEX().

SELECT SUBSTRING(Name, 0, CHARINDEX(',', Name)) AS LastName, 
               SUBSTRING(Name, CHARINDEX(',', Name) + 1, LEN(Name)) AS FirstName
FROM Customers

posted Monday, February 27, 2006 5:04 PM by Sandesh with 0 Comments




Powered by Dot Net Junkies, by Telligent Systems