Q:

How do sql can understand or convert a nvarchar is name of a table in sql server

I Waint run code in SQL SERVER
ALTER FUNCTION return_table (@table nvarchar(250))
RETURNS  TABLE 
AS
RETURN
(
     SELECT * FROM @table
)

none using PROCEDURE . THANK FOR HELP

A:

The only way to make this work is truly horrible for both aesthetic and (probably) performance reasons. It also assumes that all tables that might be passed as parameters have the same structure:
ALTER FUNCTION return_table (@table sysname)
RETURNS  TABLE 
AS
RETURN
(
     SELECT * FROM TableA where @table = 'TableA'
     UNION ALL
     SELECT * FROM TableB where @table = 'TableB'
     UNION ALL
     SELECT * FROM TableC where @table = 'TableC'
     /* add more UNIONs and SELECTs for each table that you want to use */
)

