I'm trying to make a simple function to return a random eye color. I could do this in a stored procedure but I was trying to challenge my self and try something new. I'm getting some errors, I've tried this a few different ways and I have found some documents roughly related but I'm just not skilled enough I think to understand what I did wrong and what the documents I've found are referring too syntax wise. I hope that makes sense.
CREATE FUNCTION Random_Eyes ()
RETURNS NVARCHAR(100)
AS
BEGIN
CREATE VIEW Rand_Eyes
AS
SELECT TOP 1 [Eyes]
FROM [dbo].[Eyes]
ORDER BY NEWID()
GO
DECLARE @Eyes AS NVARCHAR(100) = (SELECT [Eyes] FROM Rand_Eyes)
RETURN @Eyes
DROP VIEW Rand_Eyes
END
GO
Errors:
Msg 156, Level 15, State 1, Procedure Random_Eyes, Line 14
Incorrect syntax near the keyword 'VIEW'.Msg 102, Level 15, State 1, Procedure Random_Eyes, Line 14
Incorrect syntax near ')'Msg 178, Level 15, State 1, Line 4
A RETURN statement with a return value cannot be used in this context.Msg 102, Level 15, State 1, Line 7
Incorrect syntax near 'END'.
Any feedback or suggestions would be helpful. Thank you