Statistics

Total Posts: 34
This Year: 0
This Month: 0
This Week: 0
Comments: 174


RSS 2.0   SocialTwist Tell-a-Friend


Admin

Sign In

Navigation


Recent Posts


On this page....


Archives

 Full Archives By Category
 2007 Calendar View
<March 2010>
SunMonTueWedThuFriSat
28123456
78910111213
14151617181920
21222324252627
28293031123
45678910

Categories

CDOSYS (1) Classic ASP (10) Command Line (2) Databases (16) Excel (1) HTML (1) IIS (10) Indexing Service (1) Internet Explorer (7) Media Streaming (1) MS.Net (2) SQA (7) SQL Server (16) Windows OS (2)

Blogroll - Fav Blogs


Acknowledgments

DasBlog Theme Design by: Tom Watts
E-mail: Send mail to the author(s)
Theme Image by: dreamLogic

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

Technology Blog

This article is specific to MS SQL Server. There can be various need based scenarios where the data returned by the SELECT statement should be limited to certain length for the columns of data type VARCHAR(MAX), NVARCHAR(MAX), VARBINARY(MAX), TEXT, NTEXT, and IMAGE data types. This can be achieved using SUBSTRING or LEFT functions for specific columns in SELECT statement. But if you have a SELECT statement having many columns of the data types specified before and you want to apply data returned length limitation for each column, the better option would be to use TEXTSIZE command.

TEXTSIZE command in SQL Server can be used to limit the length of data returned for each column in a SELECT statement. This command is applicable to the columns of following data types:

  • VARCHAR(MAX)
  • NVARCHAR(MAX)
  • VARBINARY(MAX)
  • TEXT
  • NTEXT
  • IMAGE
The syntax to use the command is as given below:
SET TEXTSIZE < Specify the number of bytes here >

Example:
The below statement will set the data returned length to 200 characters and run the SELECT command with the data returned length to 200 characters for each column
SET TEXTSIZE 200
SELECT RecID, TxtCol01, TxtCol02, TxtCol03 from MyTableName


To fetch the default size of TEXTSIZE, use the below command
SELECT @@TEXTSIZE

To set the TEXTSIZE value to its default value of 2147483647 bytes, use the below command
SET TEXTSIZE 2147483647

All comments require the approval of the site owner before being displayed.
Name
E-mail
(will show your gravatar icon)
Home page

Comment (Some html is allowed: a@href@title, b, blockquote@cite, em, i, strike, strong, sub, sup, u) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

Enter the code shown (prevents robots):

Live Comment Preview