CREATE
and
ALTER
statements must be the first and only statement in a query batch, you cannot add code above or below them within a batch.
The solution is simple: terminate the batch with
GO
to execute to that point, and a new batch begins immediately:
PRINT 'One'
GO
ALTER FUNCTION ReturnTheValue2()
RETURNS INT
AS
BEGIN
RETURN 2
END
GO
PRINT 'Two'
GO