To rework my answer, LEN () is not safe to check ANSI_PADDING, since it is defined to return lengths, excluding trailing spaces, and DATALENGTH () is preferable, as AdaTheDev says.
Interestingly, ANSI_PADDING is setting the input time and that for VARCHAR this is done, but not for NVARCHAR.
Secondly, if you return a column with trailing spaces or use '=' for equality, it seems that an implicit truncation of the trailing space occurs.
SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING OFF GO CREATE TABLE [dbo].[TestFeature1]( [Id] [varchar](50) NOT NULL, [Leng] [decimal](18, 0) NOT NULL ) ON [PRIMARY] GO insert into TestFeature1 (id,leng) values ('1',100); insert into TestFeature1 (id,leng) values ('1 ',1000); -- verify no spaces inserted at end select '['+id+']', * from TestFeature1 select datalength(id), * from TestFeature1 go DROP TABLE [dbo].[TestFeature1] go SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING OFF GO CREATE TABLE [dbo].[TestFeature1]( [Id] [nvarchar](50) NOT NULL, [Leng] [decimal](18, 0) NOT NULL ) ON [PRIMARY] GO insert into TestFeature1 (id,leng) values ('1',100); insert into TestFeature1 (id,leng) values ('1 ',1000); -- verify spaces inserted at end, and ANSI_PADDING OFF was not honoured by NVARCHAR select '['+id+']', * from TestFeature1 select datalength(id), * from TestFeature1 go
Jason Zavaglia Jul 17 '09 at 13:37 2009-07-17 13:37
source share