Books online says I should be able to call an Extended Stored Procedure from a function.
Here's what i am doing:
CREATE FUNCTION page_getData
(@table varchar(500), @field varchar(500), @pCode int, @db nvarchar(50))
RETURNS VARCHAR(7000)
AS
BEGIN
DECLARE @result varchar(7000)
DECLARE @sql nvarchar(4000)
SET @sql = N'SELECT TOP 1 @stroutput=['+@field+'] FROM '+@db+'.dbo.['+@table+'] WHERE personcode='+CAST(@pCode AS nvarchar(400))
SET @result= @sql
EXEC master.dbo.[sp_executeSQL] @Sql, N'@strOutput varchar(7000) OUT', @result OUT
RETURN @result
END
GO
I [should] be able to do this right? I basically need an inline function I can pass a tablename, fieldname, dbname, and param value (in this case @pCode) and get the single value back. Anyone have anything that does this, or see whats wrong with mine?
Here's what i am doing:
CREATE FUNCTION page_getData
(@table varchar(500), @field varchar(500), @pCode int, @db nvarchar(50))
RETURNS VARCHAR(7000)
AS
BEGIN
DECLARE @result varchar(7000)
DECLARE @sql nvarchar(4000)
SET @sql = N'SELECT TOP 1 @stroutput=['+@field+'] FROM '+@db+'.dbo.['+@table+'] WHERE personcode='+CAST(@pCode AS nvarchar(400))
SET @result= @sql
EXEC master.dbo.[sp_executeSQL] @Sql, N'@strOutput varchar(7000) OUT', @result OUT
RETURN @result
END
GO
I [should] be able to do this right? I basically need an inline function I can pass a tablename, fieldname, dbname, and param value (in this case @pCode) and get the single value back. Anyone have anything that does this, or see whats wrong with mine?