Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I wrote the following code. First of all, is this TSQL or just SQL? I am not sur

ID: 3707555 • Letter: I

Question

I wrote the following code. First of all, is this TSQL or just SQL? I am not sure what the difference is. Second, how do I correctly call this function? I need to be able to send it two variables. Write a line that calls it and sends it 25 and 20.

CREATE FUNCTION GCD

(
   @num1 INT,
   @num2 INT
)

RETURNS INT

AS

BEGIN

   DECLARE @test INT

   IF ABS(@num1) < ABS(@num2)
       SELECT @test = ABS(@num1),
       @num1 = ABS(@num2),
       @num2 = @test
   ELSE
       SELECT @num1 = ABS(@num1),
       @num2 = ABS(@num2)
   SET @test = @num1 % @num2
   WHILE @test > 0
       SELECT   @num1 = @num2, @num2 = @test, @test = @num1 % @num2
       RETURN @num2
END;
GO

Explanation / Answer

The syntax to call a Transact-SQL user defined function is:

select dbo.FunctionName(@param1..)

So, the syntax to call the function mentioned in the given program is:

select dbo.GCD()

Since you didn't include any parameters while craeting the function. We can't include while calling the function.

When, You call the function using select statement, You will be asked to enter two integers as you created. So, at that time submit 25 and 20 to find the GCD of 25 and 20.