Today’s puzzle is going to be an interesting puzzle for many. The matter of the fact when I discovered this puzzle related to the stored procedure and unexpected results, I was very much surprised as well.
Let us see the puzzle right away.
First, let us following code where I have declared varchar and right after that I am storing some value in it and selecting it afterwards.
DECLARE @phone_no varchar(8) SET @phone_no=910034568 SELECT @phone_no as phone_no
When you run the above code, it gives us the following strange results.
Here is the Puzzle: Unexpected Results
When we run above query, why is it resulting result as *, instead of the value stored in a variable?
Please leave your answer in the comments section and I will publish the answers next week at the same time. I believe this puzzle is simple enough but not as easy as you think. I suggest you may ask this question to your work colleagues and see if they know the answer to this puzzle.
Here are few additional puzzles, if you want to try to tease your brain:
- SQL SERVER – Puzzle – How Does Table Qualifier Work in INSERT Statement?
- SQL SERVER – Simple Puzzle with UNION – Part 2
- SQL SERVER – Puzzle – Strange Behavior With Extra Comma in Create Table Statement
- SQL Puzzle – A Quick Fun with BitWise Operator
Update: The correct answer to this puzzle is given by Shweta in the comments section.
Please feel free to reach out to me on twitter.
Reference: Pinal Dave (https://blog.sqlauthority.com)