How to use the Decimal function from mssql

Find comprehensive JavaScript mssql.Decimal code examples handpicked from public code repositorys.

151
152
153
154
155
156
157
158
159
160
case 'bigint':
    type = mssql.BigInt;
    
    break;
case 'decimal':
    type = mssql.Decimal;
    
    break;
case 'numeric':
    type = mssql.Numeric;
fork icon6
star icon6
watch icon1

32
33
34
35
36
37
38
39
40
41
const SmallInt = sql.SmallInt;
const Int = sql.Int;
const BigInt = sql.BigInt;
const Varchar = (length) => sql.VarChar(length);
const NVarchar = (length) => sql.NVarChar(length);
const Decimal = (digits, precision) => sql.Decimal(digits, precision);
const Table = () => new sql.Table();

export {
  connection,
fork icon0
star icon4
watch icon2

47
48
49
50
51
52
53
54
55
56

params.push(new SqlParameter('Date', mssql.Date, bill.date));
params.push(new SqlParameter('Nro', mssql.VarChar(36), bill.nro));
params.push(new SqlParameter('Client', mssql.VarChar(50), bill.client));
params.push(new SqlParameter('Currency', mssql.VarChar(50), bill.currency));
params.push(new SqlParameter('Subtotal', mssql.Decimal(18, 2), bill.subtotal));
params.push(new SqlParameter('Taxes', mssql.Decimal(18, 2), bill.taxes));
params.push(new SqlParameter('Total', mssql.Decimal(18, 2), bill.total));
params.push(new SqlParameter('Paid', mssql.Int, bill.paid));
params.push(new SqlParameter('Type', mssql.VarChar(5), bill.type));
fork icon0
star icon4
watch icon4

+ 11 other calls in file

153
154
155
156
157
158
159
160
161
162
}

async function processCsvRows (context, transaction, preparedStatement, refreshData) {
  for (const columnObject of refreshData.functionSpecificData) {
    if (columnObject.tableColumnType === 'Decimal') {
      await preparedStatement.input(columnObject.tableColumnName, sql.Decimal(columnObject.precision, columnObject.scale))
    } else {
      await preparedStatement.input(columnObject.tableColumnName, sql[`${columnObject.tableColumnType}`])
    }
  }
fork icon3
star icon0
watch icon0

51
52
53
54
55
56
57
58
59
60
//     const rateId = p.rateId
//     sql_pool.request()
//     .input('from', sql.NVarChar, `${from}`)
//     .input('to', sql.NVarChar, `${to}`)
//     .input('address', sql.NVarChar, `${address}`)
//     .input('amount', sql.Decimal(14,8), `${amount}`)
//     .input('rateId', sql.NVarChar, `${rateId}`)
//     .query(`INSERT INTO [_scpx_xs_tx] VALUES (GETUTCDATE(), @from, @to, @address, @amount, @rateId, 'CHANGELLY')`)
//     .then((result) => {
//         console.log(`changelly_sign - xs_tx save ok (amount=${amount})`, result.rowsAffected);
fork icon0
star icon1
watch icon2

312
313
314
315
316
317
318
319
320
321
switch (param.type) {
  case 'integer':
    type = mssql.Int
    break
  case 'number':
    type = mssql.Decimal(param.maxLength, param.decimals)
    break
  case 'date':
    type = mssql.Date
    break
fork icon1
star icon0
watch icon2

+ 3 other calls in file

56
57
58
59
60
61
62
63
64
65
//       .input('Current0CPUTemp', sql.Int, data.Current0CPUTemp)
//       .input('Current0LEDTemp', sql.Int, data.Current0LEDTemp)
//       .input('Current1', sql.Decimal(10, 5), data.Current1)
//       .input('Current1CPUTemp', sql.Int, data.Current1CPUTemp)
//       .input('Current1LEDTemp', sql.Int, data.Current1LEDTemp)
//       .input('Current2', sql.Decimal(10, 5), data.Current2)
//       .input('Current2CPUTemp', sql.Int, data.Current2CPUTemp)
//       .input('Current2LEDTemp', sql.Int, data.Current2LEDTemp)
//       .input('Current3', sql.Decimal(10, 5), data.Current3)
//       .input('Current3CPUTemp', sql.Int, data.Current3CPUTemp)
fork icon0
star icon0
watch icon0

+ 35 other calls in file

496
497
498
499
500
501
502
503
504
505
  type: sql.Float,
  required: true,
},
{
  name: 'AMOUNT',
  type: sql.Decimal(18, 8),
  required: true,
},
{
  name: 'D_PASS2',
fork icon0
star icon0
watch icon0

+ 3 other calls in file

70
71
72
73
74
75
76
77
78
79
function getSqlType(typeName)
{
    switch(typeName) {
        case 'sql.Bit':              return sql.Bit;
        case 'sql.BigInt':           return sql.BigInt;
        case 'sql.Decimal':          return sql.Decimal;
        case 'sql.Float':            return sql.Float;
        case 'sql.Int':              return sql.Int;
        case 'sql.Money':            return sql.Money;
        case 'sql.Numeric':          return sql.Numeric;
fork icon0
star icon0
watch icon0

+ 5 other calls in file

34
35
36
37
38
39
40
41
42
43
             VALUES (@userId, @productId, @quantity, @price, @name)`;
let preppedSql = new sql.PreparedStatement(pool);
preppedSql.input('userId', sql.VarChar(20));
preppedSql.input('productId', sql.Int);
preppedSql.input('quantity', sql.Int);
preppedSql.input('price', sql.Decimal(10, 2));
preppedSql.input('name', sql.VarChar(200));
await preppedSql.prepare(addDB);

await preppedSql.execute({userId: session.authenticatedUser, productId: id, quantity: 1, price: price, name: name});
fork icon0
star icon0
watch icon0

82
83
84
85
86
87
88
89
90
91
                                  @customerId);
SELECT SCOPE_IDENTITY() AS orderId`;

preppedSql = new sql.PreparedStatement(pool);
preppedSql.input('orderDate', sql.DateTime);
preppedSql.input('totalAmount', sql.Decimal(10, 2));
preppedSql.input('address', sql.VarChar(50));
preppedSql.input('city', sql.VarChar(40));
preppedSql.input('state', sql.VarChar(20));
preppedSql.input('postalCode', sql.VarChar(20));
fork icon0
star icon0
watch icon0

1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
//       type: sql.NVarChar(50),
//       required: true
//     },
//     {
//       name: 'QTY',
//       type: sql.Decimal(18, 8),
//       required: true
//     }
//   ]
// };
fork icon0
star icon0
watch icon0

+ 23 other calls in file

258
259
260
261
262
263
264
265
266
267
  type: sql.NVarChar(10),
  required: true
},
{
  name: 'AMOUNT',
  type: sql.Decimal(18,8),
  required: true
},
{
  name: 'MESSAGE',
fork icon0
star icon0
watch icon0

39
40
41
42
43
44
45
46
47
48

const request = pool.request()
    .input('category_id', sql.UniqueIdentifier, validatedCategoryId)
    .input('product_name', sql.VarChar(99), validatedProductName)
    .input('product_description', sql.VarChar(sql.MAX), validatedProductDescription)
    .input('product_price', sql.Decimal(10, 2), validatedProductPrice)
    .input('user_id', sql.Int, validatedProductTDId)

const result = await request.execute('sp_InsertProduct')
console.log(result)
fork icon0
star icon0
watch icon0

71
72
73
74
75
76
77
78
79
80
.input('executor', sql.UniqueIdentifier, req.loggedUser.uuid)
.input('name', sql.NVarChar(100), product.name)
.input('description', sql.NVarChar(400), product.decription)
.input('quantity', sql.SmallInt, product.quantity)
.input('price', sql.Money, product.price)
.input('weight', sql.Decimal(8,2), product.weight)
.input('sellStartDate', sql.DateTime, product.sellStartDate)
.input('category', sql.NVarChar(100), product.category)
.output('response', sql.VarChar(sql.MAX))
.execute('dbo.insertProduct')
fork icon0
star icon0
watch icon0

+ 7 other calls in file

12
13
14
15
16
17
18
19
20
21
    database: this.config.parameters.SQL_database,
    connectionTimeout: this.config.parameters.SQL_connectionTimeout
};
this.types = {
    INT: sql.Int,
    DECIMAL: sql.Decimal(18, 5),
    STRING: sql.VarChar(8000),
    DATE: sql.DateTime,
    BIT: sql.bit
}
fork icon0
star icon0
watch icon5

120
121
122
123
124
125
126
127
128
.input('idUsuarioRegistro', sql.Int, dtoOrden.idUsuarioRegistro)
.input('fechaRegistro', sql.DateTime, new Date(dtoOrden.fechaRegistro))
.input('idPrefactura', sql.Int, dtoOrden.idPrefactura)
.input('idFactura', sql.Int, dtoOrden.idFactura)
.input('baja', sql.Bit, dtoOrden.baja)
.input('monto', sql.Decimal(18, 2), dtoOrden.monto)
.input('objectId', sql.VarChar(50), dtoOrden.objectId)
.input('factAutomatico', sql.VarChar(50), dtoOrden.factAutomatica)
.query(query);
fork icon0
star icon0
watch icon3

+ 5 other calls in file

12
13
14
15
16
17
18
19
20
21
    database: this.config.parameters.SQL_database,
    connectionTimeout: this.config.parameters.SQL_connectionTimeout
};
this.types = {
    INT: sql.Int,
    DECIMAL: sql.Decimal(18, 2),
    STRING: sql.VarChar(8000),
    DATE: sql.DateTime,
    BIT: sql.bit
}
fork icon0
star icon0
watch icon7

+ 6 other calls in file

79
80
81
82
83
84
85
86
87
88
if (columnProperty.CHARACTER_MAXIMUM_LENGTH < 0 || !columnProperty.CHARACTER_MAXIMUM_LENGTH) {
  columnProperty.CHARACTER_MAXIMUM_LENGTH = 100000;
}
switch (columnProperty.DATA_TYPE.toLowerCase()) {
  case 'decimal':
    type = mssql.Decimal(columnProperty.NUMERIC_PRECISION, columnProperty.NUMERIC_SCALE);
    break;
  case 'varchar':
    type = mssql.VarChar(columnProperty.CHARACTER_MAXIMUM_LENGTH + numberCharactersSpecials);
    break;
fork icon0
star icon0
watch icon1

+ 3 other calls in file