Can some one tell me that how can i get the multiple or single value results of dynamic query into a local variables.
e.g in following codes i want to store the values of fname into local variables
CODE 1:
Create Procedure Getnames @tableName VARCHAR(100)
AS
BEGIN
DECLARE @Query VARCHAR(5000)
Set @Query = 'SELECT fname FROM ' + @tableName
Execute @Query
END
CODE 2:
Create Procedure GetName @tableName VARCHAR(100), @id INT
AS BEGIN DECLARE @Query VARCHAR(5000)
SET @Query = 'SELECT fname FROM ' + @tableName + ' WHERE id = ' + @id
Execute @Query
END