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

Jesus - God Thinks of you.

ASP.NET 4.0 Feature - URL Routing

Tips on JQuery Intellisense in VS 2008