Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 123»»»

ANSI_PADDING Expand / Collapse
Author
Message
Posted Saturday, December 17, 2011 1:28 PM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Sunday, October 5, 2014 10:21 AM
Points: 2,717, Visits: 3,855
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
Post #1223505
Posted Saturday, December 17, 2011 3:32 PM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Friday, October 17, 2014 8:13 AM
Points: 9,926, Visits: 11,188
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
SQL Server MVP
SQLblog.com
@SQL_Kiwi
Post #1223507
Posted Sunday, December 18, 2011 9:33 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Tuesday, October 14, 2014 10:58 AM
Points: 5,333, Visits: 25,272
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
Post #1223566
Posted Monday, December 19, 2011 12:45 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 1:42 PM
Points: 13,239, Visits: 11,018
Great question, thanks!



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

Member of LinkedIn. My blog at LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1223640
Posted Monday, December 19, 2011 12:53 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 3:07 AM
Points: 6,040, Visits: 8,322
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 MVP
Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
Post #1223644
Posted Monday, December 19, 2011 1:19 AM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Friday, October 17, 2014 8:13 AM
Points: 9,926, Visits: 11,188
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
SQL Server MVP
SQLblog.com
@SQL_Kiwi
Post #1223660
Posted Monday, December 19, 2011 1:23 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, October 16, 2014 4:46 AM
Points: 1,355, Visits: 491
That's a good question, thanks!
Post #1223661
Posted Monday, December 19, 2011 1:34 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 3:07 AM
Points: 6,040, Visits: 8,322
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 MVP
Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
Post #1223663
Posted Monday, December 19, 2011 2:51 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Friday, October 11, 2013 8:39 AM
Points: 58, 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.
Post #1223692
Posted Monday, December 19, 2011 5:32 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, February 6, 2014 4:15 AM
Points: 1,242, Visits: 1,546
good one. Learn new thing !!!



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

Post #1223757
« Prev Topic | Next Topic »

Add to briefcase 123»»»

Permissions Expand / Collapse