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»»»

LIKE Expand / Collapse
Author
Message
Posted Wednesday, June 23, 2010 8:42 PM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Yesterday @ 4:56 PM
Points: 8,271, Visits: 8,717
Comments posted to this topic are about the item LIKE

Tom
Post #942196
Posted Wednesday, June 23, 2010 10:05 PM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Today @ 3:58 PM
Points: 985, Visits: 2,194
Good question.

For some reason I thought it could be True because of some weird implicit conversion, so I came up with this code to get my correct answer:

DECLARE @a CHAR(2);
DECLARE @b INT;

SET @a = '1 ';
SET @b = 1;

IF @a = @b AND @a LIKE @b AND @b NOT LIKE @a BEGIN
PRINT 'True';
END ELSE BEGIN
PRINT 'False';
END

...and then realized that Tom was asking about same datatype. Right answer for the wrong reason.
Post #942213
Posted Thursday, June 24, 2010 2:29 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Today @ 7:56 AM
Points: 1,658, Visits: 6,001
A good idea, but a bit too easy to guess! Even though I failed to come up with an example, I got it right as the obvious answer was 'not possible', therefore for there to be any point asking the question, the answer had to be 'possible'!
Post #942294
Posted Thursday, June 24, 2010 2:42 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Tuesday, August 27, 2013 4:28 AM
Points: 1,248, Visits: 779
Toreador (6/24/2010)
A good idea, but a bit too easy to guess! Even though I failed to come up with an example, I got it right as the obvious answer was 'not possible', therefore for there to be any point asking the question, the answer had to be 'possible'!


Likewise


_____________________________________________________________________
"The difficult tasks we do immediately, the impossible takes a little longer"
Post #942299
Posted Thursday, June 24, 2010 4:25 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Monday, February 17, 2014 8:01 AM
Points: 1,682, Visits: 446
Now this will work

declare @a varchar(16)
set @a ='a '
declare @b varchar(16)
set @b ='a'

if @a = @b and @a like @b and @b not like @a
print 'zzz'



- Pradyothana


http://www.msqlserver.com
Post #942345
Posted Thursday, June 24, 2010 5:32 AM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: 2 days ago @ 10:58 AM
Points: 819, Visits: 832
I knew it had to be trailing spaces. It's always trailing spaces...

-----
a haiku...

NULL is not zero
NULL is not an empty string
NULL is the unknown
Post #942369
Posted Thursday, June 24, 2010 7: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: Friday, April 11, 2014 12:29 PM
Points: 3,924, Visits: 1,586
Even though I got it right and know its possible but when executed in SSMS 2005 it returned error.

Msg 139, Level 15, State 1, Line 0
Cannot assign a default value to a local variable.
Msg 139, Level 15, State 1, Line 0
Cannot assign a default value to a local variable.
Msg 137, Level 15, State 2, Line 3
Must declare the scalar variable "@a".


SQL DBA.
Post #942440
Posted Thursday, June 24, 2010 7:40 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 3:31 PM
Points: 11,949, Visits: 10,982
Toreador (6/24/2010)
A good idea, but a bit too easy to guess! Even though I failed to come up with an example, I got it right as the obvious answer was 'not possible', therefore for there to be any point asking the question, the answer had to be 'possible'!


This logic is hilarious!!! It reminds me of the discussion in the Princess Bride between Wesley and the "inconceivable" guy about which glass has the poison in it.

As funny as it was I followed pretty much the same train of thought.


_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #942444
Posted Thursday, June 24, 2010 7:46 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 3:13 PM
Points: 2,409, Visits: 3,435
Sounds like an interview question.
Post #942450
Posted Thursday, June 24, 2010 7:52 AM


SSC-Insane

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

Group: General Forum Members
Last Login: Today @ 4:09 PM
Points: 22,475, Visits: 30,155
SanjayAttray (6/24/2010)
Even though I got it right and know its possible but when executed in SSMS 2005 it returned error.

Msg 139, Level 15, State 1, Line 0
Cannot assign a default value to a local variable.
Msg 139, Level 15, State 1, Line 0
Cannot assign a default value to a local variable.
Msg 137, Level 15, State 2, Line 3
Must declare the scalar variable "@a".


Code provided in the question is using SQL Server 2008 syntax, that's why it didn't work for you in SQL Server 2005 SSMS.



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 #942458
« Prev Topic | Next Topic »

Add to briefcase 123»»»

Permissions Expand / Collapse