0

Hi,

I need help in getting this function,

In oracle, least(2, 5, 12, 3) would return 2

Do we have similar function in TD or how do we do.

Thanks for Regards, TDHelp

flag

1 Answer

1

Teradata doesn't have a built-in least function.

You could have your DBA install the Teradata UDFs for popular Oracle functions pack that contains a least() function, although that UDF only handles two arguments. If you are going to keep doing a lot of Oracle-like stuff, it might be a good idea to install this pack anyway.

To apply the two-argument UDF least to more arguments, you can do:

  least(least(a,b),c)
  least(least(least(a,b),c),d)

You could also use a CASE statement like this:

-- for two values
case when a < b then a
     else b
end

-- for three values
case when a < b then
     case when a < c then a
         else c
     end
     else -- b < a
         case when b < c
             then b
             else c
         end
end

And so on, but the number of lines of code you have to write becomes big really fast if more values need to be compared.

link|flag

Your Answer

Get an OpenID
or

Not the answer you're looking for? Browse other questions tagged or ask your own question.