SQL Quiz – Why Error when Executing SELECT statements

Let us start our very first blog post with a quiz. Thanks Pune User Group for inviting me for the guest blog post. Run following T-SQL Code in SSMS. There are total of five lines. Three T-SQL statements separated by two horizontal lines.

SELECT MAX(OBJECT_IDFROM sys.objects
______________________________________
SELECT MIN(OBJECT_IDFROM sys.objects
______________________________________
SELECT COUNT(OBJECT_IDFROM sys.objects

Now when you execute individual lines only it will give you error as

Msg 2812, Level 16, State 62, Line 1
Could not find stored procedure ‘______________________________________’.

However, when you executed all the five statement together it will give you following resultset.

d

What is the reason of the same?

Please post your answer in the comments section. If you cannot figure out the answer here is the hint.

Author: Pinal Dave is principal author of SQLAuthority.com and technology evangelist.

 

Pinal Dave is a Pluralsight Developer Evangelist. He has authored 11 SQL Server database books, 17 Pluralsight courses and have written over 3200 articles on the database technology on his blog at a http://blog.sqlauthority.com. Along with 11+ years of hands on experience he holds a Masters of Science degree and a number of certifications, including MCTS, MCDBA and MCAD (.NET). His past work experiences include Technology Evangelist at Microsoft and Sr. Consultant at SolidQ.

Leave a Reply