Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


wildcards


wildcards

Author
Message
Hany Helmy
Hany Helmy
SSCrazy
SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)

Group: General Forum Members
Points: 2530 Visits: 1108
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! w00t

I want my point back ;-)
Hany Helmy
Hany Helmy
SSCrazy
SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)

Group: General Forum Members
Points: 2530 Visits: 1108
asanga (9/10/2013)
CREATE TABLE
,INSERT nothing
,receive 2?

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

Don`t worry; this question is exception! :-)
Hany Helmy
Hany Helmy
SSCrazy
SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)

Group: General Forum Members
Points: 2530 Visits: 1108
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".

Crazy
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". w00t

Couldn`t agree more!
+1
Hany Helmy
Hany Helmy
SSCrazy
SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)

Group: General Forum Members
Points: 2530 Visits: 1108
I am really amazed of the 16 people (as of now) who got it right! w00t

Hope one of them will post a reply explaining how he got the result without throwing an error.
Ford Fairlane
Ford Fairlane
SSCommitted
SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)

Group: General Forum Members
Points: 1860 Visits: 836
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





Danny Ocean
Danny Ocean
Ten Centuries
Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)

Group: General Forum Members
Points: 1354 Visits: 1549
Hany Helmy (9/11/2013)
I am really amazed of the 16 people (as of now) who got it right! w00t

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" . :crazySmile

What a horrible question...

Thanks
Vinay Kumar
-----------------------------------------------------------------
Keep Learning - Keep Growing !!!
www.GrowWithSql.com
Vera-428803
Vera-428803
Ten Centuries
Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)

Group: General Forum Members
Points: 1112 Visits: 443
Since 'Steppenwolf' is longer than 10 characters, no values are inserted.
Thus the result of the select is 0.
Carlo Romagnano
Carlo Romagnano
Hall of Fame
Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)

Group: General Forum Members
Points: 3629 Visits: 3236
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.
Hany Helmy
Hany Helmy
SSCrazy
SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)

Group: General Forum Members
Points: 2530 Visits: 1108
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! w00t

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" . :crazySmile

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.
Carlo Romagnano
Carlo Romagnano
Hall of Fame
Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)

Group: General Forum Members
Points: 3629 Visits: 3236
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]%'


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