SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


ANSI_PADDING


ANSI_PADDING

Author
Message
Jason Selburg
Jason Selburg
SSChampion
SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)

Group: General Forum Members
Points: 13993 Visits: 4137
Comments posted to this topic are about the item ANSI_PADDING

______________________________________________________________________

Personal Motto: Why push the envelope when you can just open it?

If you follow the direction given HERE you'll likely increase the number and quality of responses you get to your question.

Jason L. Selburg
Paul White
Paul White
SSC Guru
SSC Guru (79K reputation)SSC Guru (79K reputation)SSC Guru (79K reputation)SSC Guru (79K reputation)SSC Guru (79K reputation)SSC Guru (79K reputation)SSC Guru (79K reputation)SSC Guru (79K reputation)

Group: General Forum Members
Points: 79386 Visits: 11400
Good question. If you had wanted to be really sneaky...


DECLARE @Example TABLE (col1 VARCHAR(10))
INSERT @Example VALUES ('X'), ('X' + SPACE(1)), ('X' + SPACE(2))

SELECT COUNT_BIG(*) FROM @Example AS e WHERE col1 LIKE 'X' + SPACE(1)
SELECT COUNT_BIG(*) FROM @Example AS e WHERE col1 LIKE N'X' + SPACE(1)





Paul White
SQLPerformance.com
SQLblog.com
@SQL_Kiwi
bitbucket-25253
bitbucket-25253
SSC-Dedicated
SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)

Group: General Forum Members
Points: 34659 Visits: 25280
SQL Kiwi (12/17/2011)
Good question. If you had wanted to be really sneaky...


DECLARE @Example TABLE (col1 VARCHAR(10))
INSERT @Example VALUES ('X'), ('X' + SPACE(1)), ('X' + SPACE(2))

SELECT COUNT_BIG(*) FROM @Example AS e WHERE col1 LIKE 'X' + SPACE(1)
SELECT COUNT_BIG(*) FROM @Example AS e WHERE col1 LIKE N'X' + SPACE(1)



OUCH

If everything seems to be going well, you have obviously overlooked something.

Ron

Please help us, help you -before posting a question please read

Before posting a performance problem please read
Koen Verbeeck
Koen Verbeeck
SSC Guru
SSC Guru (145K reputation)SSC Guru (145K reputation)SSC Guru (145K reputation)SSC Guru (145K reputation)SSC Guru (145K reputation)SSC Guru (145K reputation)SSC Guru (145K reputation)SSC Guru (145K reputation)

Group: General Forum Members
Points: 145066 Visits: 13349
Great question, thanks!


How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?
My blog at SQLKover.

MCSE Business Intelligence - Microsoft Data Platform MVP
Hugo Kornelis
Hugo Kornelis
SSC-Dedicated
SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)

Group: General Forum Members
Points: 34219 Visits: 13109
Thanks for the question, Jason.

I only got it right because "3, 3, 1" was not in the answer options - that was the answer I was looking for after reading the question. I am also a bit disappointed that this part of the answer is not explained. One of the links included in the explanation includes this quote:
When the right side of a LIKE predicate expression features a value with a trailing space, SQL Server does not pad the two values to the same length before the comparison occurs.

That quote only reinforces my expectation that the third query should return 1. Can anyone explain to me why it doesn't?

(And, while you're at it, you might also want to explain the even stranger behaviour demonstrated by the query Paul posted in this topic).


Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
Paul White
Paul White
SSC Guru
SSC Guru (79K reputation)SSC Guru (79K reputation)SSC Guru (79K reputation)SSC Guru (79K reputation)SSC Guru (79K reputation)SSC Guru (79K reputation)SSC Guru (79K reputation)SSC Guru (79K reputation)

Group: General Forum Members
Points: 79386 Visits: 11400
Hugo Kornelis (12/19/2011)
That quote only reinforces my expectation that the third query should return 1. Can anyone explain to me why it doesn't?

It is 'explained' (perhaps 'documented' would be a better term) in the last paragraph of Pattern Matching in Search Conditions

And, while you're at it, you might also want to explain the even stranger behaviour demonstrated by the query Paul posted in this topic).

This point needs LIKE (Transact-SQL) in the sub-section 'Pattern Matching by Using LIKE'. Hilarious...


DECLARE @Example TABLE (col1 VARCHAR(10))
INSERT @Example VALUES ('X'), ('X' + SPACE(1)), ('X' + SPACE(2))

DECLARE @ESC1 CHAR = '['
DECLARE @ESC2 NCHAR = '['

SELECT COUNT_BIG(*) FROM @Example AS e WHERE col1 LIKE 'X' + SPACE(1) ESCAPE @Esc1
SELECT COUNT_BIG(*) FROM @Example AS e WHERE col1 LIKE 'X' + SPACE(1) ESCAPE @Esc2





Paul White
SQLPerformance.com
SQLblog.com
@SQL_Kiwi
palotaiarpad
palotaiarpad
Hall of Fame
Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)

Group: General Forum Members
Points: 3109 Visits: 852
That's a good question, thanks!
Hugo Kornelis
Hugo Kornelis
SSC-Dedicated
SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)

Group: General Forum Members
Points: 34219 Visits: 13109
Thanks, Paul!

I won't say "it all makes sense now" - but at least, I now have at least a passing chance of remembering what might have happened and where to look for an explanation if I ever encounter this counter-intuitive behaviour in the wild.


Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
InvisibleCat
InvisibleCat
SSC Eights!
SSC Eights! (810 reputation)SSC Eights! (810 reputation)SSC Eights! (810 reputation)SSC Eights! (810 reputation)SSC Eights! (810 reputation)SSC Eights! (810 reputation)SSC Eights! (810 reputation)SSC Eights! (810 reputation)

Group: General Forum Members
Points: 810 Visits: 606
Great question.

Got it wrong as I did not fully read the INSERT statement.

Still, it's ok, the lesson learnt today is, always read the question properly, even on a Monday morning. :-)
Danny Ocean
Danny Ocean
Hall of Fame
Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)

Group: General Forum Members
Points: 3386 Visits: 1549
good one. Learn new thing !!!

Thanks
Vinay Kumar
-----------------------------------------------------------------
Keep Learning - Keep Growing !!!
www.GrowWithSql.com
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search