SgDotNet
Singapore Professional .NET User Group -For Cool Developers

SQL Substring

rated by 0 users
This post has 1 Reply | 1 Follower

Top 500 Contributor
Posts 2
flyingdance Posted: 04-30-2008 7:47 PM

Hi all,

If I have a string like this, 1-2-3,

how do I get the 2 using SQL query?

The number of digits between the '-' can be more than one and also it can be a letter instead of number.

For example, I want to do something like "SELECT [this] FROM [table]". I want to know what to put in '[this]' so that I can get the center one between the dash.

Anyone can help? Thanks!

cheers, YC
Top 25 Contributor
Posts 157

Using your example, try SELECT SUBSTRING('1-2-3', 3, 1)or to select from a table, try the following syntax:

SELECT SUBSTRING(colname, start, length) FROM tablename

Page 1 of 1 (2 items) | RSS
Copyright SgDotNet 2004-2008
Powered by Community Server (Commercial Edition), by Telligent Systems