User-Defined Functions in Sql Server SSMS

  • Thread starter WWGD
  • Start date
  • #1
WWGD
Science Advisor
Gold Member
7,031
10,618
TL;DR Summary
Trying to figure out syntax problem with Syntax for function that takes as inputs two Real number and outputs the square root of the sum of the squares of the two numbers.
Hi, trying to write a user-defined function in SSMS Sql Server .that takes two Real numbers and outputs the square root of the
sum of their squares:

Line 152
CREATE FUNCTION dbo.Distance(@a Real, @b Real)
RETURNS Real
AS
BEGIN
SQRT(@a * @a + @b * @b)
END ;
GO

I re-checked the syntax for user-defined functions, but somehow I keep getting error messages .
Error Message:
Msg 102, Level 15, State 1, Procedure Distance, Line 5 [Batch Start Line 152]
Incorrect syntax near 'SQRT'.

any ideas?
 
Technology news on Phys.org
  • #2
are you missing the RETURN stmt:

RETURN SQRT(@a*@a + @b*@b);
 
  • Like
Likes WWGD
  • #3
jedishrfu said:
are you missing the RETURN stmt:

RETURN SQRT(@a*@a + @b*@b);
Excellent, that did it. My Programmability folder runneth over. Thanks.
 
  • Like
Likes jedishrfu
  • #5
  • Haha
Likes jedishrfu

Similar threads

  • Programming and Computer Science
Replies
11
Views
2K
  • Computing and Technology
Replies
1
Views
2K
  • Programming and Computer Science
Replies
4
Views
2K
  • Programming and Computer Science
Replies
8
Views
828
  • Programming and Computer Science
Replies
3
Views
1K
  • Math Proof Training and Practice
3
Replies
80
Views
4K
  • Programming and Computer Science
Replies
13
Views
7K
  • Programming and Computer Science
Replies
4
Views
6K
  • Programming and Computer Science
Replies
2
Views
2K
  • Programming and Computer Science
Replies
22
Views
5K
Back
Top