当我写这样的参数时有什么区别?我相信底部proc表示将默认值设置为null。顶部给了我一个错误:
关键字' NULL'附近的语法不正确。必须声明标量变量
CREATE PROCEDURE [dbo].[Create_Part]
@AssessmentPartId UNIQUEIDENTIFIER OUTPUT,
@assessmentPartCode VARCHAR(4) NULL,
@assessmentPartCode VARCHAR(4) NULL
AS
SET @AssessmentPartId = NEWID()
INSERT INTO dbo.tblEMISAssessmentPart (AssessmentPartId,
AssessmentPartcode, AssessmentPartCode)
VALUES (@AssessmentPartId, @assessmentPartCode,
@assessmentPartCode)
GO
vs
CREATE PROCEDURE [dbo].[Create_Part]
@AssessmentPartId UNIQUEIDENTIFIER OUTPUT,
@assessmentPartCode VARCHAR(4) = NULL,
@assessmentPartCode VARCHAR(4) = NULL
AS
SET @AssessmentPartId = NEWID()
INSERT INTO dbo.tblEMISAssessmentPart (AssessmentPartId,
AssessmentPartcode, AssessmentPartCode)
VALUES (@AssessmentPartId, @assessmentPartCode,
@assessmentPartCode)
GO
答案 0 :(得分:2)
您无法更改TSQL存储过程参数的可为空性。它们总是可以为空。这就是第一位似乎正在做的事情。
您可以为存储过程参数指定默认值,这使它们成为可选参数。这就是第二位正在做的事情。
可以使用一个参数调用第二个过程,例如
module.exports = async function () {
try {
await load();
} catch (ex) {
console.log(ex);
logger.error(ex);
}
};
async function load() {
return await new Promise((resolve, reject) => {
TableImport.findAll().then((tables) => {
for (let table of tables) {
await loadData(table.fileName, table.tableName);
}
resolve();
}).catch(function (err) {
reject(err);
})
})
};
async function loadData(location, tableName) {
return await new Promise(function (resolve, reject) {
var currentFile = path.resolve(__dirname + '/../fdb/' + location);
sequelize.query("LOAD DATA LOCAL INFILE '" + currentFile.replace('/', '//').replace(/\\/g, '\\\\') + "' INTO TABLE " + tableName + " FIELDS TERMINATED BY '|'").then(function () {
resolve(tableName);
}).catch(function (ex) {
reject();
});
});
};