I have a problem with bellow code. I am trying to insert into @ResultTable a third column that is a result of type bit of comparsion two numbers. If the val is bigger than avg(val) it should return 1 if not then 0. I know how to do it with Case but it should be possible to do it with just bit type right?
Create FUNCTION [dbo].[GetAvg](@col AvgRes READONLY)
RETURNS @ResultTable TABLE(id int, val float, result BIT)
AS
BEGIN
DECLARE @result bit
DECLARE @avgval int
SET @avgval = (select AVG(val) FROM @col)
SET @result = val > @avgval <---- I have problem right there, I get Incorrect syntax near '>'. error
Insert into @ResultTable
SELECT id, val, @result
FROM @col
RETURN
END