Using group function without table definition

Function -A-->
create FUNCTION [dbo].[FN_Test] (@Date date) RETURNS TABLE
AS RETURN
(
select * from Test;
);

Function-B--->

create FUNCTION [dbo].[FN_Test] (@Date date) RETURNS TABLE
RETURNS @table TABLE (AA int,BB varchar(50),CC varchar(100))
AS
begin
if @Date<=convert(date,getdate())
select * from Test;
else
select * from Test2;
end

My 1st function returning data without any Table definition, But my 2nd function returning data with defined table,
How can i return data without defining table based on some condition as mentioned in 2nd function.

Thank you.

create FUNCTION [dbo].[FN_Test] (@Date date) RETURNS TABLE
AS RETURN
(
select * from Test WHERE @Date<=convert(date,getdate())
UNION ALL
select * from Test2 WHERE @Date>convert(date,getdate())
)

1 Like