Hi,
In Sql Server Stored Procedure we can create dynamic queries with single or multiple parameters
Here i am passing i/p parameter as table for dynamic query
Example :
CREATE procedure sp_RetrieveBasedOnField
@TableName varchar(50) -- i/p
as
begin
declare @Query as nvarchar(255)
set @Query=N'select * from '+ @TableName +N''
exec sp_ExecuteSQL @Query
end
This is simple as we can pass our table name and executes dynamic query.
Thank you
In Sql Server Stored Procedure we can create dynamic queries with single or multiple parameters
Here i am passing i/p parameter as table for dynamic query
Example :
CREATE procedure sp_RetrieveBasedOnField
@TableName varchar(50) -- i/p
as
begin
declare @Query as nvarchar(255)
set @Query=N'select * from '+ @TableName +N''
exec sp_ExecuteSQL @Query
end
This is simple as we can pass our table name and executes dynamic query.
Thank you
No comments:
Post a Comment