Writing and Executing Dynamic Query in SQL Server example

  MSSQLSERVER   Thursday, November 5, 2015   1519 | No Comments Yet!!! | No Download | No Demo | Pawan kumar
 Tags: Writing and Executing Dynamic Query in SQL Server example 


 Database: I am making use of Microsoft Northwind database,

SQL Snippets:-


CREATE PROCEDURE Customers_GetCustomer
      @CustId CHAR(5)
AS
BEGIN
      DECLARE @SQL NVARCHAR(2000)
      SET @SQL = 'SELECT ContactName FROM Customers WHERE CustomerId = @CustomerId'
      EXEC sp_executesql @SQL, N'@CustomerId CHAR(5)', @CustomerId = @CustId
END