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 Thursday, June 24, 2010 8:02 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, February 20, 2014 12:48 PM
Points: 137, Visits: 162
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'!


Ditto here.
Post #942464
Posted Thursday, June 24, 2010 8:06 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: 2 days ago @ 4:21 PM
Points: 7,928, Visits: 9,653
Lynn Pettis (6/24/2010)
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.


It's surprising how quickly I have come to use SQL 2008 syntax - if I'd written that just a few weeks earlier it would have been in SQL 2000 syntax (so it would have worked in 2000, 2005, and 2008).


Tom
Post #942468
Posted Thursday, June 24, 2010 8:10 AM
Say Hey Kid

Say Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey Kid

Group: General Forum Members
Last Login: Tuesday, December 9, 2014 8:18 PM
Points: 665, Visits: 405
OCTom (6/24/2010)
Sounds like an interview question.

At least as the first part of a possible two-parter ("So you think it's possible? OK, please give me an example....") .
Post #942472
Posted Thursday, June 24, 2010 8:25 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: 2 days ago @ 4:21 PM
Points: 7,928, Visits: 9,653
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'!

I wondered whether that reasoning would be common and perhaps lead to a success rate close to 100%. I thought that if the success rate looked too high I could devise a question where the obvious answer was the correct one for my next attempt and see if it attracted a high failure rate. But the success rate turne out to be reasonable - 246 people (about a third of those trying it so far) have got it wrong, so perhaps not too easy after all.


Tom
Post #942482
Posted Thursday, June 24, 2010 8:26 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Today @ 9:33 AM
Points: 1,832, Visits: 6,650
I've probably been answering too many of these questions recently so always looking for the trick!
Post #942487
Posted Thursday, June 24, 2010 10:40 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Friday, September 5, 2014 2:00 PM
Points: 2,160, Visits: 2,191
I figured it was possible because of trailing spaces, and tested it, but I messed my test rig up, so I got it wrong...

Thanks for the question!
Post #942573
Posted Thursday, June 24, 2010 1:14 PM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, August 28, 2014 8:53 PM
Points: 1,388, Visits: 3,039
Lynn Pettis (6/24/2010)
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.

Just to make the difference plain.... SQL 2005 requires a separate SET or SELECT to establish the value of a local variable.
declare @a varchar(6); set @a ='a      ';
declare @b varchar(6); select @b = 'a';
if @a = @b and @a like @b and @b not like @a print 'zzz'

Post #942658
Posted Thursday, June 24, 2010 11:32 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Saturday, January 22, 2011 8:42 PM
Points: 18, Visits: 39
This is what I absolutely hate about SQL Server. A string is a f**king string, no matter whether it's got spaces on it at the end.

Jeez.
Post #942809
Posted Friday, June 25, 2010 12:55 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Sunday, November 2, 2014 11:03 PM
Points: 2,133, Visits: 371
good question ... thanks...
Post #942829
Posted Friday, June 25, 2010 3:05 PM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Tuesday, December 16, 2014 9:58 AM
Points: 2,280, Visits: 3,069
Richard Tatterton (6/24/2010)
This is what I absolutely hate about SQL Server. A string is a f**king string, no matter whether it's got spaces on it at the end.

Jeez.


While this is true.... a string is a string, but the deviation here is the method used to evaluate the strings. Part of the ANSI standard is to make strings evaluated with "=" the same length before comparison and this is not a requirement for pattern matching. Like uses pattern matches so the string does not have to be equal.




My blog: http://jahaines.blogspot.com
Post #943356
« Prev Topic | Next Topic »

Add to briefcase ««123»»

Permissions Expand / Collapse