Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scalar Function To Return the Result of A Select

I want a function to find the maximum allowable length of a field; executed as cmd.ExecuteScalar().

This definition fails, why?

CREATE FUNCTION getPWLen
(
)
RETURNS int
AS
BEGIN
   return select max(len((password))) as return_value from tblSec
END
GO
like image 406
elbillaf Avatar asked Oct 17 '25 04:10

elbillaf


1 Answers

No need for a column alias, also wrap the SELECT in brackets

...
return (select max(len(password)) from tblSec)
...
like image 67
gbn Avatar answered Oct 18 '25 16:10

gbn