Passing Object Names as Parameters

In SQL Server 2014, if you pass an object name as a parameter to a stored procedure, SQL Server attempts to treat it as a table-valued parameter unless the object name is used either as an argument in a WHERE clause or in a dynamic SQL query. For example, the code in Listing 25.15 generates an error message when you try to create the stored procedure.

LISTING 25.15 Attempting to Create a Stored Procedure by Using a Parameter to Pass in a Table Name

CREATE  proc find_data @table varchar(128)asselect * from @tableGO/* outputMsg 1087, Level 16, State 1, Procedure find_data, Line 4 Must declare the table variable "@table".*/

As you can see, when the parameter is used in the FROM

Get Microsoft SQL Server 2014 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.