Hi there, I have been working on a stored procedure to return a value based on a number of variables, including table name. This was posted earlier. The advice recieved was great but as I only need a single value returned noy a recordset I thought I might ask more advice. heres the sp
CREATE PROCEDURE spGetThisTableField @ReturnVal as Integer output,
@strTableName varchar(50) , --Recipes
@strCompareFld as varchar(50), --RecipeKey
@strSearchValue as char(50), --9
@strFieldToReturn as varchar(50) output--PackCodeKey
--Select Recipes.packCodeKey from Recipes WHERE Recipes.RecipeKey = 9
AS
SET NOCOUNT ON
declare @SQLCommand nVarChar(200)
begin
Set @SQLCommand =('Select ' + @strFieldToReturn + ' from ' + @strTableName + ' WHERE ' + @strCompareFld + ' = ' + @strSearchValue)
end
--execute sp_executesql @SQLCommand
return @SQLCommand
GO
Rather than Return @SQLCommand I need to have @ReturnVal populated with the integer value from column @strFieldToReturn.
Regards
CREATE PROCEDURE spGetThisTableField @ReturnVal as Integer output,
@strTableName varchar(50) , --Recipes
@strCompareFld as varchar(50), --RecipeKey
@strSearchValue as char(50), --9
@strFieldToReturn as varchar(50) output--PackCodeKey
--Select Recipes.packCodeKey from Recipes WHERE Recipes.RecipeKey = 9
AS
SET NOCOUNT ON
declare @SQLCommand nVarChar(200)
begin
Set @SQLCommand =('Select ' + @strFieldToReturn + ' from ' + @strTableName + ' WHERE ' + @strCompareFld + ' = ' + @strSearchValue)
end
--execute sp_executesql @SQLCommand
return @SQLCommand
GO
Rather than Return @SQLCommand I need to have @ReturnVal populated with the integer value from column @strFieldToReturn.
Regards