SQL Server过程(参数值暂时为硬值):
DECLARE @ComCod AS VARCHAR(2) = '15'
DECLARE @LocCod AS VARCHAR(2) = '01'
DECLARE @PetDat AS VARCHAR(8) = '20180731'
DECLARE @CurrentBatchNo AS INT
EXECUTE @CurrentBatchNo = Accounts.dbo.fnApp_GetCurrentBatchNo @ComCode = @ComCod,
@LocCode = @LocCod
INSERT INTO GL_Batch_Details
(Company_Code,
Location_Code,
Fiscal_Year,
Fiscal_Month,
Batch_No,
Entry_No,
Source_Code,
Line_No,
Account_Code,
Transaction_Date,
Debit_Amount,
Credit_Amount,
Reference,
Narration,
Batch_Status,
Delete_Status)
VALUES(@ComCod /* Company_Code */,
@LocCod /* Location_Code */,
SUBSTRING(Accounts.dbo.fnApp_GetFinancialDates(@PetDat),1,4) /* Fiscal_Year */,
SUBSTRING(Accounts.dbo.fnApp_GetFinancialDates(@PetDat),9,2) /* Fiscal_Month */,
@CurrentBatchNo /* Batch_No */,
1 /* Entry_No */,
'GLC1' /* Source_Code */,
(SELECT ROW_NUMBER() OVER(ORDER BY PettyHeader.HPetComCode,
PettyHeader.HPetLocCode,
PettyHeader.HPetDate) /* Line_No */,
PettyDetail.DPetAcNo /* Account_Code */,
PettyDetail.DPetDate /* Transaction_Date */,
PettyDetail.DPetAmount /* Debit_Amount */,
0.00 /* Credit_Amount */,
PettyHeader.HPetPayee /* Reference */,
CAST(PettyHeader.HPetVouNo as varchar) +
' '+
PettyDetail.DPetDetail /* Narration */
FROM PettyHeader
INNER JOIN PettyDetail
ON PettyHeader.HPetComCode = PettyDetail.DPetComCode AND
PettyHeader.HPetLocCode = PettyDetail.DPetLocCode AND
PettyHeader.HPetDate = PettyDetail.DPetDate AND
PettyHeader.HPetVouNo = PettyDetail.DPetVouNo
WHERE (PettyHeader.HPetComCode = @ComCod) AND
(PettyHeader.HPetLocCode = @LocCod) AND
(YEAR(PettyHeader.HPetDate) = YEAR(CONVERT(date, @PetDat,111))) AND
(MONTH(PettyHeader.HPetDate) = MONTH(CONVERT(date, @PetDat, 111)))),
'1' /* Batch_Status */,
'F' /* Delete_Status */)
下面的功能代码
ALTER FUNCTION [dbo].[fnApp_GetCurrentBatchNo]
(@ComCode VARCHAR(2),
@LocCode VARCHAR(2))
RETURNS INT
AS
BEGIN
-- Declare the return variable here
DECLARE @CurrentBatchNo INT
-- Add the T-SQL statements to compute the return value here
SELECT @CurrentBatchNo = (SELECT (Last_Updated_Batch_No + 1)
FROM Provisional_Posting_Log
WHERE Company_Code = @ComCode
AND Location_Code = @LocCode)
-- Return the result of the function
RETURN @CurrentBatchNo
END
在保存我的过程时,会产生以下错误:
116级第1州第53行的消息116
如果未使用EXISTS引入子查询,则只能在选择列表中指定一个表达式。第109条消息的15级状态1的第9行
INSERT语句中的列多于VALUES子句中指定的值。 VALUES子句中的值数必须与INSERT语句中指定的列数匹配。
有人可以帮我解决这些错误吗?