Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Determine ANSI_PADDING status in TSQL Expand / Collapse
Author
Message
Posted Friday, July 27, 2012 2:42 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, December 4, 2014 7:02 AM
Points: 11, Visits: 68
Hello SQL Gurus.

I have a situation where the production databases have ANSI_PADDING on. This is what I want, as for reasons best know to the users they need to store A [Space][Space] as exactly that.

Yesterday I found that the UAT databases have ANSI_PADDING off. This is producing inconsistent test data, as you can imagine.

I was hoping that A/P might be visible on INFORMATION_SCHEMA.COLUMNS, and I would be able to set it in code. But so far I haven't been able to find how to do this.

Please can someone tell me what level ANSI_PADDING is stored - Column, Table or DB... and furthermore, what is the best way to find this out in code?

Thanks!
Post #1336318
Posted Friday, July 27, 2012 2:54 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Wednesday, July 27, 2016 2:31 AM
Points: 2,866, Visits: 4,893
SELECT	SESSIONPROPERTY('ANSI_PADDING')




Kingston Dhasian

How to post data/code on a forum to get the best help - Jeff Moden
http://www.sqlservercentral.com/articles/Best+Practices/61537/
Post #1336326
Posted Friday, July 27, 2012 7:31 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, December 4, 2014 7:02 AM
Points: 11, Visits: 68
Many thanks :)
Post #1336499
Posted Friday, July 27, 2012 12:16 PM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Wednesday, May 11, 2016 7:35 AM
Points: 1,378, Visits: 1,579
For checking ANSI_PADDING on columns:

SELECT name  column_name,
CASE is_ansi_padded
WHEN 1 THEN 'On'
ELSE 'Off'
AS [ANSI_PADDING]
FROM sys.all_columns
WHERE object_id = object_id(<table name>)



~ Lokesh Vij

Guidelines for quicker answers on T-SQL question
Guidelines for answers on Performance questions

Link to my Blog Post --> www.SQLPathy.com

Follow me @Twitter

Post #1336699
Posted Friday, July 27, 2012 12:20 PM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Wednesday, May 11, 2016 7:35 AM
Points: 1,378, Visits: 1,579
To further add (SQL Server 2012 BOL):

In a future version of Microsoft SQL Server ANSI_PADDING will always be ON and any applications that explicitly set the option to OFF will produce an error. Avoid using this feature in new development work, and plan to modify applications that currently use this feature.

Source: http://msdn.microsoft.com/en-us/library/ms187403.aspx


~ Lokesh Vij

Guidelines for quicker answers on T-SQL question
Guidelines for answers on Performance questions

Link to my Blog Post --> www.SQLPathy.com

Follow me @Twitter

Post #1336700
Posted Friday, July 27, 2012 12:21 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Yesterday @ 2:02 PM
Points: 23,174, Visits: 36,984
Lokesh Vij (7/27/2012)
For checking ANSI_PADDING on columns:

SELECT name  column_name,
CASE is_ansi_padded
WHEN 1 THEN 'On'
ELSE 'Off'
AS [ANSI_PADDING]
FROM sys.all_columns
WHERE object_id = object_id(<table name>)



Or:


SELECT
name column_name,
CASE is_ansi_padded
WHEN 1 THEN 'On'
ELSE 'Off'
AS [ANSI_PADDING]
FROM
sys.columns
WHERE
object_id = object_id(<schema.tablename>)





Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Post #1336702
Posted Friday, July 27, 2012 12:24 PM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Wednesday, May 11, 2016 7:35 AM
Points: 1,378, Visits: 1,579
Lynn Pettis (7/27/2012)
Lokesh Vij (7/27/2012)
For checking ANSI_PADDING on columns:

SELECT name  column_name,
CASE is_ansi_padded
WHEN 1 THEN 'On'
ELSE 'Off'
AS [ANSI_PADDING]
FROM sys.all_columns
WHERE object_id = object_id(<table name>)



Or:


SELECT
name column_name,
CASE is_ansi_padded
WHEN 1 THEN 'On'
ELSE 'Off'
AS [ANSI_PADDING]
FROM
sys.columns
WHERE
object_id = object_id(<schema.tablename>)




Great Lynn, I missed that.
Thanks


~ Lokesh Vij

Guidelines for quicker answers on T-SQL question
Guidelines for answers on Performance questions

Link to my Blog Post --> www.SQLPathy.com

Follow me @Twitter

Post #1336703
Posted Wednesday, April 20, 2016 1:17 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, May 13, 2016 11:33 PM
Points: 4, Visits: 70
just FYI that "is_ansi_padded" column in sys.all_columns will show as 0 if the column type is not a char, binary or variant column. If you are trying to find all columns with the ansi_padding where it actually matters you may want to limit it to those columns with something like the below.

SELECT	t.name as [table_name],
c.name as [column_name],
ty.[name] as [column_data_type],
CASE WHEN c.is_ansi_padded = 1
THEN 'On'
ELSE 'Off'
END as [ansi_padding]
FROM sys.all_columns c
inner join sys.tables t
on (c.object_id = t.object_id)
inner join sys.types ty
on (c.system_type_id = ty.system_type_id)
where t.name not like 'sys%'
and t.name not like 'MS_%'
and ty.name in ('char','varchar','binary','sql_variant','nvarchar','nchar')
order by t.name


Post #1779522
Posted Friday, April 22, 2016 9:36 AM
Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Yesterday @ 10:02 AM
Points: 3,646, Visits: 6,046
Fwiw, I prefer the a different way to check the current ansi / connection settings, using:
@@OPTIONS
I actually use a table of config values so the code is more readable, but here's the direct value comparison method:


IF @@OPTIONS & 16 > 0
PRINT 'ANSI_PADDING is ON'
ELSE
PRINT 'ANSI_PADDING is OFF'
IF @@OPTIONS & 16384 > 0
PRINT 'XACT_ABORT is ON'
ELSE
PRINT 'XACT_ABORT is OFF'




SQL DBA,SQL Server MVP('07, '08, '09)

Prosecutor James Blackburn, in closing argument in the "Fatal Vision" murders trial: "If in the future, you should cry a tear, cry one for them [the murder victims]. If in the future, you should say a prayer, say one for them. And if in the future, you should light a candle, light one for them."
Post #1780140
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse