Given this:
Where @ref is a Column within another table, @Table is a table name and @Type is the Table type.
How can I get the value of this function:
Executing it with:
Results in this: Error converting data type nvarchar to bigint.
Or depening on how the @Query is constructed:
Could not find stored procedure 'SELECT @Result = MAX(SettlementDay) FROM Headers_Info WHERE (Type = 'P')'.
However, copying and pasting the SQL in the '' from the error message results in the correct answer!
Am I making sense?
--
Bubba
woogoo
Code:
CREATE FUNCTION [dbo].[GetCSVExpectedF]
(
@Table nvarchar(32),
@Type char(1)
)
RETURNS
datetime
AS
BEGIN
DECLARE @ID bigint ;
DECLARE @Ref nvarchar(32) ;
DECLARE @Result datetime ;
DECLARE @Query nvarchar(1024) ;
SELECT @ref = Reference FROM CSV_LookUp WHERE ((FileName = @Table) AND (Type = @Type)) ;
SELECT @ID = MAX(ID) from CSV_Schedule WHERE (Settlement_Date < GETDATE()) ;
SET @Query = N'SELECT @Result = ' + @ref + ' FROM CSV_Schedule where ID = (' + @ID + ');' ;
EXEC @Query ;
RETURN @Result ;
END
Where @ref is a Column within another table, @Table is a table name and @Type is the Table type.
How can I get the value of this function:
Executing it with:
Code:
SELECT [dbo].[GetCSVExpectedF] (N'Info', N'P') ;
Or depening on how the @Query is constructed:
Could not find stored procedure 'SELECT @Result = MAX(SettlementDay) FROM Headers_Info WHERE (Type = 'P')'.
However, copying and pasting the SQL in the '' from the error message results in the correct answer!
Am I making sense?
--
Bubba
woogoo