Hi,
Since i cannot use table name as parameter, I would like do this, is it possible or is there a better way of doing it.
The below function return a sql query as a string.
CREATE FUNCTION SQLSELECT(@P_TABLE VARCHAR(50),@P_KEY VARCHAR(5))
RETURNS VARCHAR(5000)
AS
BEGIN
DECLARE @MSTR VARCHAR(100)
SET @MSTR = 'SELECT * FROM '+ @P_TABLE+' WHERE EMP_NO='''+@P_KEY+''''
RETURN @MSTR
END
Now i use a function that returns a table value.
CREATE FUNCTION SQLSELECT1 ()
RETURNS TABLE
AS
RETURN SELECT * FROM (SELECT SQLUSEREN.SQLSELECT('EMPLOYEE','02814')abc)xyz
GO
The output of this function is SELECT * FROM EMPLOYEE WHERE EMP_NO='02814'
Can i not use the same function SQLSELECT1 or some other way to return the table value after excution of the sql statement that is returned.
If this is not possible what else is a way to achive this functionality.
Thanks and Regards
Dinesh