Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Advertise
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
Article Discussions
»
Article Discussions by Author
»
Discuss content posted by Jack Corbett
»
ANSI PADDING, Trailing Whitespace, and...
39 posts, Page 4 of 4
««
«
1
2
3
4
ANSI PADDING, Trailing Whitespace, and Variable Length Character Colum
Rate Topic
Display Mode
Topic Options
Author
Message
stephen.hendricks
stephen.hendricks
Posted Thursday, July 30, 2009 4:10 PM
SSC Veteran
Group: General Forum Members
Last Login: Friday, August 07, 2009 5:46 PM
Points: 295,
Visits: 67
Thanks for your efforts. I appreciate how generous you have been with your time; and for free, no less.
============================================================
I believe I found the missing link between animal and civilized man. It is us. -Konrad Lorenz, Nobel laureate (1903-1989)
Post #762826
Jack Corbett
Jack Corbett
Posted Thursday, July 30, 2009 5:08 PM
SSCrazy Eights
Group: General Forum Members
Last Login: Today @ 8:11 AM
Points: 8,186,
Visits: 7,970
No problem. You made me curious so I had to do something.
Jack Corbett
Applications Developer
Don't let the good be the enemy of the best. --
Paul Fleming
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
How to Post Performance Problems
Crosstabs and Pivots or How to turn rows into columns Part 1
Crosstabs and Pivots or How to turn rows into columns Part 2
Post #762838
Matt Campbell-473914
Matt Campbell-473914
Posted Friday, July 31, 2009 9:35 AM
Forum Newbie
Group: General Forum Members
Last Login: Monday, August 03, 2009 8:44 AM
Points: 2,
Visits: 7
I take no chances when it comes to SQL Server and trailing spaces. I always use
LTRIM(RTRIM(
col_name
))
when selecting data or updating data if the field is any kind of string-holder, and I do so on left- and right-hand side comparison clauses too. Basically, anywhere I refer to a table field that is a string container, it always gets this kind of treatment. It adds overhead of course to the query but unless there is a critical timing issue (and there oughtn't be if you wrote the app right), using this "Kill 'em all let God sort 'em out" approach has never failed me.
I also always Trim() string values from ADO recordset fields to be doubly-sure. Just because I am paranoid doesn't mean I'm not right!
Post #763207
Jack Corbett
Jack Corbett
Posted Friday, July 31, 2009 9:53 AM
SSCrazy Eights
Group: General Forum Members
Last Login: Today @ 8:11 AM
Points: 8,186,
Visits: 7,970
Matt,
The only problem with LTRIM(RTRIM(column)) in comparison (WHERE or JOIN) clauses it that you no longer give the optimizer the option to use an index seek, the best it can do it scan as it HAS to evaluate every row using the function. And, as the chart shows, for equality/inequality that is unnecessary.
Certainly using it when inserting/updating a value is okay, although, in my opinion, the UI/business layer should clean this up.
Jack Corbett
Applications Developer
Don't let the good be the enemy of the best. --
Paul Fleming
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
How to Post Performance Problems
Crosstabs and Pivots or How to turn rows into columns Part 1
Crosstabs and Pivots or How to turn rows into columns Part 2
Post #763223
Jeff Moden
Jeff Moden
Posted Friday, July 31, 2009 10:46 AM
SSChampion
Group: General Forum Members
Last Login: Yesterday @ 9:01 PM
Points: 20,164,
Visits: 13,702
Matt Campbell (7/31/2009)
I take no chances when it comes to SQL Server and trailing spaces. I always use
LTRIM(RTRIM(
col_name
))
when selecting data or updating data if the field is any kind of string-holder, and I do so on left- and right-hand side comparison clauses too. Basically, anywhere I refer to a table field that is a string container, it always gets this kind of treatment. It adds overhead of course to the query but unless there is a critical timing issue (and there oughtn't be if you wrote the app right), using this "Kill 'em all let God sort 'em out" approach has never failed me.
I also always Trim() string values from ADO recordset fields to be doubly-sure. Just because I am paranoid doesn't mean I'm not right!
Heh... and as Jack points out, that pretty much eliminates any chance at real peformance if the proper indexes are available. I'd suggest a different approach in the future.
--Jeff Moden
"
RBAR
is pronounced "ree-bar" and is a "Modenism" for "
R
ow-
B
y-
A
gonizing-
R
ow".
"Data isn't the only thing that's supposed to have Integrity."
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."
For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Post #763258
Ol'SureHand
Ol'SureHand
Posted Monday, August 03, 2009 12:29 AM
SSC Veteran
Group: General Forum Members
Last Login: Yesterday @ 6:04 PM
Points: 230,
Visits: 473
Jack Corbett (7/31/2009)
Matt,
The only problem with LTRIM(RTRIM(column)) in comparison (WHERE or JOIN) clauses it that you no longer give the optimizer the option to use an index seek, the best it can do it scan as it HAS to evaluate every row using the function. And, as the chart shows, for equality/inequality that is unnecessary.
Certainly using it when inserting/updating a value is okay, although, in my opinion, the UI/business layer should clean this up.
Fully agree! I have to issue these warnings to all entusiastic developers who rush into using functions and "clever" UDFs and end up peppering the WHERE clause with such stuff that almost kills the server...
And Thank You Jack once again for taking the trouble and being so thorough.
Post #763906
Ol'SureHand
Ol'SureHand
Posted Monday, August 03, 2009 12:38 AM
SSC Veteran
Group: General Forum Members
Last Login: Yesterday @ 6:04 PM
Points: 230,
Visits: 473
Jeff Moden (9/13/2008)
Jack Corbett (9/13/2008)
[Jack said:] [ANSI_PADDING] is turned off by default at the Database level, which is odd considering the ability to turn it off is going to be deprecated. Oh well, who said MS had to be consistent?
Heh... I wish MS would stop deprecating useful things.
Guys, can we do anything about it? Like write to Microsoft or something?
If ANSI_PADDING OFF is deprecated, and the ON becomes the only setting, I reckon that eliminates the difference between CHAR and VARCHAR.
Why bother having 2 data types that behave the same way and use the same amount of space. . . oh, that's not so, in the case of VARCHAR, it will use 2 extra bytes for the length!!!!!
Post #763910
Jeff Moden
Jeff Moden
Posted Monday, August 03, 2009 2:59 AM
SSChampion
Group: General Forum Members
Last Login: Yesterday @ 9:01 PM
Points: 20,164,
Visits: 13,702
It's not quite that bad... with ANSI PADDING ON, VARCHAR can have trailing spaces if they've been assigned. It won't automatically pad spaces to the total width of the column. I can live with that... I just worry about others that can't. It would be like them setting ANSI NULLS to OFF permanently... that would absolutely kill a lot of my code where I depend on NULL being treated for what it is... unknown.
I suspect there's not much we can do.
--Jeff Moden
"
RBAR
is pronounced "ree-bar" and is a "Modenism" for "
R
ow-
B
y-
A
gonizing-
R
ow".
"Data isn't the only thing that's supposed to have Integrity."
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."
For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Post #763943
Jack Corbett
Jack Corbett
Posted Monday, August 03, 2009 7:00 AM
SSCrazy Eights
Group: General Forum Members
Last Login: Today @ 8:11 AM
Points: 8,186,
Visits: 7,970
Ol'SureHand (8/3/2009)
Jeff Moden (9/13/2008)
Jack Corbett (9/13/2008)
[Jack said:] [ANSI_PADDING] is turned off by default at the Database level, which is odd considering the ability to turn it off is going to be deprecated. Oh well, who said MS had to be consistent?
Heh... I wish MS would stop deprecating useful things.
Guys, can we do anything about it? Like write to Microsoft or something?
If ANSI_PADDING OFF is deprecated, and the ON becomes the only setting, I reckon that eliminates the difference between CHAR and VARCHAR.
Why bother having 2 data types that behave the same way and use the same amount of space. . . oh, that's not so, in the case of VARCHAR, it will use 2 extra bytes for the length!!!!!
The best option is
CONNECT
. MS takes
CONNECT
seriously especially if you can get others to vote for it.
Jack Corbett
Applications Developer
Don't let the good be the enemy of the best. --
Paul Fleming
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
How to Post Performance Problems
Crosstabs and Pivots or How to turn rows into columns Part 1
Crosstabs and Pivots or How to turn rows into columns Part 2
Post #764023
« Prev Topic
|
Next Topic »
39 posts, Page 4 of 4
««
«
1
2
3
4
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2010 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use