您可以跳过 node-mssql 中的输入/输出设置,只需像往常一样选择标量函数。
功能
CREATE FUNCTION [dbo].[udfTestScalar] (
-- Add the parameters for the function here
@F1 FLOAT
,@F2 FLOAT
)
RETURNS NVARCHAR(100)
AS
BEGIN
-- Declare the return variable here
DECLARE @N1 NVARCHAR(100)
-- Add the T-SQL statements to compute the return value here
SET @N1 = N'Hi there'
RETURN @N1
END
index.js
var sql = require('mssql');
var config = {
user: 'user',
password: 'password',
server: 'localhost',
database: 'db'
};
var connection = new sql.Connection(config, function(err) {
var request = new sql.Request(connection);
request.query("SELECT dbo.udfTestScalar(12345.123, 12345.456) as result", function(err, recordsets) {
console.log(recordsets[0].result);
});
});
输出
% node index.js
'Hi there'