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

wildcards Expand / Collapse
Author
Message
Posted Wednesday, September 11, 2013 12:06 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Today @ 4:38 AM
Points: 1,139, Visits: 520
The answer is definitely wrong! I ran the exact same query on SQL Server 2008 R2 & I got the same error everyone got:

Msg 8152, Level 16, State 14, Line 3
String or binary data would be truncated.
The statement has been terminated.

(0 row(s) affected)

How come parameter
mychar VARCHAR(10)

and you insert 11 char value?!
'Steppenwolf'

Of course the insert statement will fail!

I want my point back
Post #1493453
Posted Wednesday, September 11, 2013 12:14 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Today @ 4:38 AM
Points: 1,139, Visits: 520
asanga (9/10/2013)
CREATE TABLE
,INSERT nothing
,receive 2?

...I will never get any points... ;(

Don`t worry; this question is exception!
Post #1493456
Posted Wednesday, September 11, 2013 12:17 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Today @ 4:38 AM
Points: 1,139, Visits: 520
Danny Ocean (9/10/2013)
handkot (9/10/2013)
I got an error: "String or binary data would be truncated. The statement has been terminated."
(0 row(s) affected)

Just because of "Steppenwolf" having length 11. So insert statement is not executed successfully.

Correct answer should be "0".


I think, nobody check this question before post on SSC. This question is completely wrong.
Still i didn't believe that this question is posted by "Steve Jones - SSC Editor".

Couldn`t agree more!
+1
Post #1493457
Posted Wednesday, September 11, 2013 12:21 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Today @ 4:38 AM
Points: 1,139, Visits: 520
I am really amazed of the 16 people (as of now) who got it right!

Hope one of them will post a reply explaining how he got the result without throwing an error.
Post #1493458
Posted Wednesday, September 11, 2013 12:36 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Yesterday @ 6:58 PM
Points: 1,678, Visits: 750
The question is broken...

Msg 8152, Level 16, State 14, Line 5
String or binary data would be truncated.
The statement has been terminated.

(0 row(s) affected)

Had to try it after seeing so many failed responses.


Hope this helps...

Ford Fairlane
Rock and Roll Detective





Post #1493460
Posted Wednesday, September 11, 2013 12:36 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
Hany Helmy (9/11/2013)
I am really amazed of the 16 people (as of now) who got it right!

Hope one of them will post a reply explaining how he got the result without throwing an error.


If you only see the like condition and give answer then you will be in those 16 people.
(but i am not in those 16. I gave answer as "0" . )

What a horrible question...




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

Post #1493461
Posted Wednesday, September 11, 2013 12:49 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: Tuesday, July 1, 2014 11:59 PM
Points: 897, Visits: 355
Since 'Steppenwolf' is longer than 10 characters, no values are inserted.
Thus the result of the select is 0.

Post #1493462
Posted Wednesday, September 11, 2013 12:49 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Monday, July 21, 2014 6:24 AM
Points: 2,451, Visits: 2,342
The correct exceution of the query depends on ansi_warnings
set ansi_warnings off
DECLARE @i TABLE( mychar VARCHAR(10));

INSERT @i VALUES ('Steve'), ('Stephan'), ('Stephanie')
, ('Sterling'), ('Steppenwolf')

SELECT mychar
FROM @i
WHERE mychar LIKE 'Ste[^p]%'

It returns two rows in ONE resultset.
The question asks how many results ...?
The resultset is only ONE.
Post #1493463
Posted Wednesday, September 11, 2013 12:52 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Today @ 4:38 AM
Points: 1,139, Visits: 520
Danny Ocean (9/11/2013)
Hany Helmy (9/11/2013)
I am really amazed of the 16 people (as of now) who got it right!

Hope one of them will post a reply explaining how he got the result without throwing an error.


If you only see the like condition and give answer then you will be in those 16 people.
(but i am not in those 16. I gave answer as "0" . )

What a horrible question...

Sorry I didn`t get it! the problem in this question is the 11 char value in the Insert statement not the LIKE condition!

I even copy & paste the same batch from the question (JUST TO MAKE SURE I WAS RIGHT NOT DOING THIS ALL THE TIME), got the same error.
Post #1493464
Posted Wednesday, September 11, 2013 12:54 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Monday, July 21, 2014 6:24 AM
Points: 2,451, Visits: 2,342
A version of the query without the use of local table:
SELECT *
FROM (
VALUES ('Steve')
, ('Stephan')
, ('Stephanie')
, ('Sterling')
, ('Steppenwolf')) AS A(mychar )
WHERE mychar LIKE 'Ste[^p]%'

Post #1493467
« Prev Topic | Next Topic »

Add to briefcase ««12345»»»

Permissions Expand / Collapse