Writing and Executing Dynamic Query in SQL Server example

  MSSQLSERVER   Thursday, November 5, 2015   1073 | 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

 

Post Comments

if you have some suggestion, question, request on Writing and Executing Dynamic Query in SQL Server example.

Please use the comment box to express your views.

 

Comments: