0
ALTER FUNCTION [dbo].[customers_udfMin2] 
(
    @decission tinyint 
)
RETURNS int

AS
BEGIN
    -- Declare the return variable here
    DECLARE @min int
    Declare @default int = 10
    -- Add the T-SQL statements to compute the return value here

    if (@decission = 1)
    Begin
     SELECT @min = MIN(customers.cus_id) from customers
    End
    else  
     RETURN 0

     Return @default 

END

in every case it returns @default , y ? even i sent 1 as a parameter.

2
Contributors
3
Replies
11
Views
4 Years
Discussion Span
Last Post by HunainHafeez
1

Your return @default is not within your if..else block so it always executes. You can use begin..end if needed in your else block.

 if (@decission = 1)
      BEGIN
           --some code
      END
 ELSE
     BEGIN
           --some code
     END

Edited by JorgeM

0

sorry bro, not working , same problem

but i learned to put BEGIN..END, thanks

Edited by HunainHafeez

0

ok ok, i got the problem JorGem, actually i'm not returning @min, that's why because i tried values other thatn 1 and for that else worked well, so i put return in IF block and that worked for 1.

Thanks :)

Edited by HunainHafeez: updated result

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.