Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 398
  • Last Modified:

BEGIN / END Wrapper with RETURN command. Why?

With TSQL functions, wrapping the RETURN command in BEGIN and END commands seems to be mandatory.  (See the attached code snippet.)  The two commands seem superfluous.  After all, functions in other programming languages (VB.NET, VBA, PHP, JavaScript...) don't require the equivalent of RETURN be wrapped in BEGIN and END.  So why are they required with TSQL?
CREATE FUNCTION dbo.centigrade_to_farenheit (@centigrade float)
RETURNS float
WITH EXECUTE AS CALLER
AS
BEGIN  -- Why is this BEGIN command necessary?
     RETURN((@centigrade * 1.8) + 32.0)
END  -- Why is this END command necessary?
GO

Open in new window

0
jdana
Asked:
jdana
3 Solutions
 
Aneesh RetnakaranDatabase AdministratorCommented:
you need to mention the BEGIN END in the function definition except for Inline Table-valued Functions
0
 
chapmandewCommented:
Because that his how the language is....  :)
0
 
HoggZillaCommented:
The body of a function in SQL Server is defined by a BEGIN and END. That's it, no reason, it just is. :-)
0
 
jdanaAuthor Commented:
It is what it is.  Thanks!
0
 
MohammedUCommented:
You have to follow the syntax and the question is why you nee BEGIN and END can be answered only the MS sql developers....
Every language has its own syntax and it doesn't need to be the same as other languages...
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now