Dynamic SQL in SQL Server - Introduction

Dynamic SQL is nothing but SQL query that is generated programmatically.

For example, we can get records of any table using the below Stored Procedure which implements Dynamic SQL

CREATE PROC GETDETAILSBYTABLENAME(@TableName varchar(50))
AS
BEGIN
Declare @SQLQuery VarChar(5000)

SELECT @SQLQuery = 'SELECT * FROM ' + @TableName

Exec ( @SQLQuery)
END

Comments

Popular posts from this blog

“Unable to retrieve the metadata for …” Error while using ASP.NET MVC 3

2012 - > 2013 : Happy New Year

Visual Studio 2013 and .NET 4.5.1