Everybody knows the min and max value properties in .Net.
Dim i As Int32 = Int32.MaxValue
The values represents the smallest and the largest value for a datatype. For some of us it might be interesting to get this information within a stored procedure.
Show Sql Source Code for SAQ_GET_DOMAIN_LIMIT.Stored Procedure source code
call sa_make_object('function', 'SAQ_GET_DOMAIN_LIMIT');
ALTER FUNCTION "DBA"."SAQ_GET_DOMAIN_LIMIT"($domainName long varchar, $min bit default 1, $width int default 0, $scale int default 0) returns long varchar
begin
declare _result long varchar;
case $domainName
when 'smallint' then
if $min=1 then
set _result = '-32768';
else
set _result = '32767';
end if
when 'unsigned smallint' then
if $min=1 then
set _result = '0';
else
set _result = '65535';
end if
when 'integer' then
if $min=1 then
set _result = '-2147483648';
else
set _result = '2147483647';
end if
when 'unsigned integer' then
if $min=1 then
set _result = '0';
else
set _result = '4294967295';
end if
when 'int' then
if $min=1 then
set _result = '-2147483648';
else
set _result = '2147483647';
end if
when 'unsigned int' then
if $min=1 then
set _result = '0';
else
set _result = '4294967295';
end if
when 'tinyint' then
if $min=1 then
set _result = '0';
else
set _result = '255';
end if
when 'unsigned tinyint' then
if $min=1 then
set _result = '0';
else
set _result = '255';
end if
when 'bigint' then
if $min=1 then
set _result = '-9223372036854775808';
else
set _result = '9223372036854775807';
end if
when 'unsigned bigint' then
if $min=1 then
set _result = '0';
else
set _result = '18446744073709551615';
end if
when 'bit' then
if $min=1 then
set _result = '0';
else
set _result = '1';
end if
when 'decimal' then
set _result = replace(space($width-$scale),' ','9')||'.'||replace(space($scale),' ','9');
if $min=1 then
set _result = '-'||_result;
end if
when 'double' then
set _result = replace(space($width-$scale),' ','9')||'.'||replace(space($scale),' ','9');
if $min=1 then
set _result = '-'||_result;
end if
when 'float' then
set _result = replace(space($width-$scale),' ','9')||'.'||replace(space($scale),' ','9');
if $min=1 then
set _result = '-'||_result;
end if
when 'real' then
set _result = replace(space($width-$scale),' ','9')||'.'||replace(space($scale),' ','9');
if $min=1 then
set _result = '-'||_result;
end if
when 'numeric' then
set _result = replace(space($width-$scale),' ','9')||'.'||replace(space($scale),' ','9');
if $min=1 then
set _result = '-'||_result;
end if
end;
if right (_result,1)='.' then set _result = replace (_result, '.', '') end if;
return _result;
end;
Stored Procedure Test
select *,
SAQ_GET_DOMAIN_LIMIT(DOMAIN_NAME,1,"precision",1) as MIN_VALUE,
SAQ_GET_DOMAIN_LIMIT(DOMAIN_NAME,0,"precision",1) as MAX_VALUE
from sysdomain
Stored Procedure Resultset
| domain_id | domain_name | type_id | precision | MIN_VALUE | MAX_VALUE |
|---|---|---|---|---|---|
| 1 | smallint | 5 | 5 | -32768 | 32767 |
| 2 | integer | 4 | 10 | -2147483648 | 2147483647 |
| 3 | numeric | 2 | -.9 | .9 | |
| 4 | float | 7 | 7 | -999999.9 | 999999.9 |
| 5 | double | 8 | 15 | -99999999999999.9 | 99999999999999.9 |
| 6 | date | 9 | |||
| 7 | char | 1 | |||
| 8 | char | 1 | |||
| 9 | varchar | 12 | |||
| 10 | long varchar | -1 | |||
| 11 | binary | -2 | |||
| 12 | long binary | -4 | |||
| 13 | timestamp | 11 | |||
| 14 | time | 10 | |||
| 19 | tinyint | -6 | 3 | 0 | 255 |
| 20 | bigint | -5 | 20 | -9223372036854775808 | 9223372036854775807 |
| 21 | unsigned int | -9 | 10 | 0 | 4294967295 |
| 22 | unsigned smallint | -10 | 5 | 0 | 65535 |
| 23 | unsigned bigint | -11 | 21 | 0 | 18446744073709551615 |
| 24 | bit | -7 | 1 | 0 | 1 |
| 27 | decimal | 2 | -.9 | .9 | |
| 28 | varbinary | -2 | |||
| 29 | uniqueidentifier | -15 | |||
| 30 | varbit | -16 | |||
| 31 | long varbit | -17 | |||
| 32 | xml | -18 | |||
| 33 | nchar | -12 | |||
| 34 | nchar | -12 | |||
| 35 | nvarchar | -13 | |||
| 36 | long nvarchar | -14 |