Click here to Skip to main content
15,919,931 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
The code below won’t execute
SQL
Go
Create function task_hospitals
(@vic_id int , @HOS int ) returns int
As
Begin
Return ( @Hos = COUNT(*)
From patients
Where victim_id =@vic_id);
End


What I have tried:

I don’t know what’s wrong to be honest
Posted
Updated 11-Dec-21 23:36pm
v2
Comments
Richard MacCutchan 12-Dec-21 3:18am    
I suspect you need a SELECT verb before COUNT: SQL COUNT(), AVG() and SUM() Functions[^].

1 solution

You can't assign a value to an input parameter like that:
SQL
CREATE FUNCTION task_hospitals
(@vic_id INT, @HOS INT ) RETURNS INT
AS
BEGIN
RETURN (SELECT COUNT(*)
        FROM patients
        WHERE victim_id = @vic_id);
END
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900