Substring Function in Sql Server

Substring function, as the name suggests, is used to get a sub-string from a string. A sub-string is some part of a string. Mostly, when talking about sub-strings, we mean non-empty sub-strings.

Substring is an important string manpulation function and is invariably a part of any programming environment.

General syntax for obtaining a sub-string is

substring(string, startingindex, length)

A sample code for substring in T-SQL is :

select substring(custName,1,5) from tab_Customer

1 is starting location and 5 is the length of the substring to be obtained. So we are trying to obtain a substring of first 5 letters of all customer names


Guest Author: Aag18 Sep 2013

Microsoftae SQL Serverae 2008 Implementation and Maintenance (Pro-Certification) (Hardcover) The Microsoft Training Kit text for SQL Server 2005 exam 70-431 (for which Hotel was a contributor, but not primary author) is one of the best technical books I have ever come across. I have read every page at least twice, some sections several times. It covers a wealth of complex material in an organized, well-written manner. I hoped the SQL 2008 version would be an update of the SQL 2005 text, adding coverage for new or updated SQL 2008 features.Alas, the SQL 2008 edition has been completely rewritten, with Hotek as the only author. I have read the first 100 pages and intend to read the entire text, but am not happy. The content is poorly organized, poorly edited and flat-out incorrect on some important points. (Errors regarding multiple instances were commented on by earlier reviewers. This error was not just stated once, but was repeated.) In more than one end-of-section mini-quiz, the questions are for material not covered in that section.Hotek claims, more than once, to have worked on millions of databases . Huh? If he worked on a different database every hour, and worked a ten-hour day for 300 days per year, that would total out to 30,000 databases a year, or 300,000 over ten years. Mike would have to have worked over thirty years to get close to his first million databases!That said, Hotek is a really smart guy, with tons of SQL Server experience. His contributions to the SQL 2005 text were interesting and useful. Unfortunately, his expertise does not translate to authorship of books like this, and he has been poorly served by his technical editors (if there were any) at Microsoft Press.NOTE: I submitted the above two-star review on March 19, 2009. I subsequently completed the entire book, some sections more than once, but found no reason to upgrade the rating, either for content or editing. Most of the questions on the Transcender practice exam cannot be answered using Hotek's book. My advice to those prepping for the 70-432 exam is to use the excellent text for the 70-431 exam, augmented by study of new SQL 2008 features like file streaming and policies. Good luck!

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: