You are currently offline, waiting for your internet to reconnect

INF: Behavior of ANSI_PADDING

This article was previously published under Q154886
SUMMARY
This article discusses the behavior of the SET ANSI_PADDING optionavailable with SQL Server version 6.5 and later.
MORE INFORMATION
One of the new SET options introduced with SQL Server 6.5 is ANSI_PADDING.The "What's New in SQL Server 6.5" guide mentions that when ANSI_PADDING ison, Varchar values are padded with blanks and Varbinary values arepadded with nulls. Note that this does not mean that all variable columnsstart behaving like fixed length columns by padding all values entered intothe column. It means that if a value is entered in a variable column withtrailing blanks or nulls, the trailing blanks or nulls are notautomatically removed.

The running of the following script in ISQL/w or Query Analyzer illustrates the behavior of ANSI_PADDING. It builds a table with Char, Varchar and Varbinary columns and inserts values both with and without trailing blanks. The script does this twice, once with ANSI_PADDING on and once with it off, to demonstrate that the trailing blanks are inserted into all columns for the first row when the option is on, and are not inserted when the option is off. It also illustrates that the option does not cause the Varchar columns to be padded out to their full length. It only prevents the truncation of trailing blanks supplied by the user.
USE pubsGOSET ANSI_PADDING ONGOPRINT 'Testing with ANSI_PADDING ON'GOCREATE TABLE t1 (charcol char(16) NULL, varcharcol varchar(16) NULL, varbinarycol varbinary(8))GOINSERT INTO t1 VALUES ('No blanks', 'No blanks', 0x00ee)INSERT INTO t1 VALUES ('Trailing blank ', 'Trailing blank ', 0x00ee00)GO  SELECT 'CHAR'='>' + charcol + '<', 'VARCHAR'='>' + varcharcol + '<',varbinarycolFROM t1GOSET ANSI_PADDING OFFGOPRINT 'Testing with ANSI_PADDING OFF'GOCREATE TABLE t2 (charcol char(16) NULL, varcharcol varchar(16) NULL, varbinarycol varbinary(8))GOINSERT INTO t2 VALUES ('No blanks', 'No blanks', 0x00ee)INSERT INTO t2 VALUES ('Trailing blank ', 'Trailing blank ', 0x00ee00)GOSELECT 'CHAR'='>' + charcol + '<', 'VARCHAR'='>' + varcharcol + '<', varbinarycolFROM t2GODROP TABLE t1GODROP TABLE t2GO				
Properties

Article ID: 154886 - Last Review: 03/14/2005 20:03:16 - Revision: 3.3

  • Microsoft SQL Server 6.5 Standard Edition
  • Microsoft SQL Server 7.0 Standard Edition
  • Microsoft SQL Server 2000 Standard Edition
  • kbinfo kbnetwork KB154886
Feedback