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.

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

sorry bro, not working , same problem

but i learned to put BEGIN..END, thanks

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 :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.