Here Mudassar Ahmed Khan has explained with an example, how to use the SQL Server sp_executesql command and how to pass parameters to sp_executesql command in SQL Server.
Dynamic SQL Query can be executed with parameters using the sp_executesql command in SQL Server.
The sp_executesql command is supported in SQL Server versions i.e. 2000, 2005, 2008, 2008R2, 2012, 2014 or higher.