SgDotNet
Singapore Professional .NET User Group -For Cool Developers

SQL Substring

Latest post 05-01-2008 12:02 AM by bronkman. 1 replies.
  • 04-30-2008 7:47 PM

    SQL Substring

    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
  • 05-01-2008 12:02 AM In reply to

    Re: SQL Substring

    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