• Sgar... (4/15/2016)


    In above examples you have used Set @dbname= 'database name'.

    I am taking this input from Stored procedure input. How can you help?

    In that case you do not need the SET, because the parameter will be set to the value you pass in the EXECUTE statement.

    Please read very carefully all that has been said in this topic. And then read up on SQL injection. Do all that before coding any further line of code that takes you on the path of using a variable or parameter to determine the database to use.


    Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
    Visit my SQL Server blog: https://sqlserverfast.com/blog/
    SQL Server Execution Plan Reference: https://sqlserverfast.com/epr/