1

Topic: Error in CREATE FUNCTION

It is necessary to create function which deduces the most widespread component.
Here request:
SELECT TOP (1) WITH TIES ingredient_number, COUNT (*)
FROM Food_composition
GROUP BY ingredient_number
ORDER BY COUNT (*) DESC
Here function which swears on an error:
CREATE FUNCTION the_most_common_ingredient
RETURNS TABLE
AS RETURN
(
SELECT TOP (1) WITH TIES ingredient_number, COUNT (*)
FROM Food_composition
GROUP BY ingredient_number
ORDER BY COUNT (*) DESC)
Error - A RETURN statement with a return value cannot be used in this context.

2

Re: Error in CREATE FUNCTION

cglcz;
COUNT (*) AS CNTT

3

Re: Error in CREATE FUNCTION

cglcz;

CREATE FUNCTION the_most_common_ingredient ()
RETURNS TABLE
AS RETURN
(
SELECT TOP (1) WITH TIES ingredient_number, COUNT (*) AS [cnt]
FROM Food_composition
GROUP BY ingredient_number
ORDER BY COUNT (*) DESC)

Only if at you function does not accept entering parameters what for selected it instead of representation?

4

Re: Error in CREATE FUNCTION

All works, thanks