If have a stored procedure like follow:
```
CREATE PROCEDURE [dbo].[proc_TestDecimalOutput]
@PerfectNumber decimal(18,2) OUTPUT
AS
BEGIN
SET @PerfectNumber = 10.35;
END
GO
```
you will end-up with this generated code:
```
public int ProcTestDecimalOutput(out decimal? perfectNumber)
{
var perfectNumberParam = new SqlParameter { ParameterName = "@PerfectNumber", SqlDbType = SqlDbType.Decimal, Direction = ParameterDirection.Output };
var procResultParam = new SqlParameter { ParameterName = "@procResult", SqlDbType = SqlDbType.Int, Direction = ParameterDirection.Output };
Database.ExecuteSqlCommand("EXEC @procResult = [dbo].[proc_TestDecimalOutput] @PerfectNumber OUTPUT", perfectNumberParam, procResultParam);
if (IsSqlParameterNull(perfectNumberParam))
perfectNumber = null;
else
perfectNumber = (decimal) perfectNumberParam.Value;
return (int) procResultParam.Value;
}
```
Output parameters must specify scale and precision for decimal, and size for varchar, otherwise default values will be used and in the case of decimal, if I'm not wrong is precision 29, scale 0 (29, 0).
Parameters should be in somehow generated as follow:
```
var perfectNumberParam = new SqlParameter
{
ParameterName = "@PerfectNumber",
SqlDbType = SqlDbType.Decimal,
Direction = ParameterDirection.Output,
Precision = 18,
Scale = 2
};
```
I'm not a master of master db :) query but this could be a point where we can start:
```
SELECT
SCHEMA_NAME(SCHEMA_ID) AS [Schema],
SO.name AS [ObjectName],
SO.Type_Desc AS [ObjectType (UDF/SP)],
P.parameter_id AS [ParameterID],
P.name AS [ParameterName],
TYPE_NAME(P.user_type_id) AS [ParameterDataType],
P.precision,
P.scale,
P.max_length AS [ParameterMaxBytes],
P.is_output AS [IsOutPutParameter]
FROM
sys.objects AS SO
INNER JOIN sys.parameters AS P ON SO.OBJECT_ID = P.OBJECT_ID
WHERE
SO.OBJECT_ID IN ( SELECT OBJECT_ID
FROM
sys.objects
WHERE
TYPE IN ('P','FN'))
ORDER BY
[Schema], SO.name, P.parameter_id
```
It returns, max_length for varchar (Size property on SqlParameter), and precision and scale for decimal.
```
CREATE PROCEDURE [dbo].[proc_TestDecimalOutput]
@PerfectNumber decimal(18,2) OUTPUT
AS
BEGIN
SET @PerfectNumber = 10.35;
END
GO
```
you will end-up with this generated code:
```
public int ProcTestDecimalOutput(out decimal? perfectNumber)
{
var perfectNumberParam = new SqlParameter { ParameterName = "@PerfectNumber", SqlDbType = SqlDbType.Decimal, Direction = ParameterDirection.Output };
var procResultParam = new SqlParameter { ParameterName = "@procResult", SqlDbType = SqlDbType.Int, Direction = ParameterDirection.Output };
Database.ExecuteSqlCommand("EXEC @procResult = [dbo].[proc_TestDecimalOutput] @PerfectNumber OUTPUT", perfectNumberParam, procResultParam);
if (IsSqlParameterNull(perfectNumberParam))
perfectNumber = null;
else
perfectNumber = (decimal) perfectNumberParam.Value;
return (int) procResultParam.Value;
}
```
Output parameters must specify scale and precision for decimal, and size for varchar, otherwise default values will be used and in the case of decimal, if I'm not wrong is precision 29, scale 0 (29, 0).
Parameters should be in somehow generated as follow:
```
var perfectNumberParam = new SqlParameter
{
ParameterName = "@PerfectNumber",
SqlDbType = SqlDbType.Decimal,
Direction = ParameterDirection.Output,
Precision = 18,
Scale = 2
};
```
I'm not a master of master db :) query but this could be a point where we can start:
```
SELECT
SCHEMA_NAME(SCHEMA_ID) AS [Schema],
SO.name AS [ObjectName],
SO.Type_Desc AS [ObjectType (UDF/SP)],
P.parameter_id AS [ParameterID],
P.name AS [ParameterName],
TYPE_NAME(P.user_type_id) AS [ParameterDataType],
P.precision,
P.scale,
P.max_length AS [ParameterMaxBytes],
P.is_output AS [IsOutPutParameter]
FROM
sys.objects AS SO
INNER JOIN sys.parameters AS P ON SO.OBJECT_ID = P.OBJECT_ID
WHERE
SO.OBJECT_ID IN ( SELECT OBJECT_ID
FROM
sys.objects
WHERE
TYPE IN ('P','FN'))
ORDER BY
[Schema], SO.name, P.parameter_id
```
It returns, max_length for varchar (Size property on SqlParameter), and precision and scale for decimal.