lagyossarian
09-01-2005, 03:34 PM
I'm trying to write the following stored proc. The key is that I have a field that I'm creating that will be returned in the resultset for binding to a report. This field, DueDate, has conditional logic to determine its calculation. I'm getting the following error:
Server: Msg 156, Level 15, State 1, Procedure ir_ReportApprovalPastDue, Line 28
Incorrect syntax near the keyword 'AS'.
[Microsoft][ODBC SQL Server Driver]Syntax error or access violation
It doesn't seem to like how I'm trying to assign the result of the DATEADD function. Any help or guidance is sincerely appreciated. Thanks in advance.
Greg
CREATE PROCEDURE dbo.ir_ReportApprovalPastDue
@DateComp DateTime
AS
DECLARE
@DayNum int
SELECT
A.Status,
A.Cost,
A.Invoice_no,
A.Price_Sold,
IE.First_Payment,
IM.RFI_No,
IM.Customer_No,
IM.Invoice_Date,
IM.Status,
IM.Salesperson,
IM.Sales_Code,
M.LastName,
M.FirstName,
M.Company,
CASE
WHEN (IE.First_Payment = NULL) OR (DATEDIFF(dd, GETDATE(), IE.First_Payment) = 0) THEN
DATEADD(Day, 30, IM.Invoice_Date) AS DueDate
ELSE IE.First_Payment AS DueDate
END
FROM
Active_Inventory AS A,
Inv_Extra_Data AS IE,
Inv_Master AS IM,
ML_HCC AS M
WHERE
A.Status = 'Approval' AND
A.Invoice_no != 0 AND
IM.Status = 'Appr' AND
DueDate <= CONVERT(datetime, CONVERT(int, GETDATE()))
GO
Server: Msg 156, Level 15, State 1, Procedure ir_ReportApprovalPastDue, Line 28
Incorrect syntax near the keyword 'AS'.
[Microsoft][ODBC SQL Server Driver]Syntax error or access violation
It doesn't seem to like how I'm trying to assign the result of the DATEADD function. Any help or guidance is sincerely appreciated. Thanks in advance.
Greg
CREATE PROCEDURE dbo.ir_ReportApprovalPastDue
@DateComp DateTime
AS
DECLARE
@DayNum int
SELECT
A.Status,
A.Cost,
A.Invoice_no,
A.Price_Sold,
IE.First_Payment,
IM.RFI_No,
IM.Customer_No,
IM.Invoice_Date,
IM.Status,
IM.Salesperson,
IM.Sales_Code,
M.LastName,
M.FirstName,
M.Company,
CASE
WHEN (IE.First_Payment = NULL) OR (DATEDIFF(dd, GETDATE(), IE.First_Payment) = 0) THEN
DATEADD(Day, 30, IM.Invoice_Date) AS DueDate
ELSE IE.First_Payment AS DueDate
END
FROM
Active_Inventory AS A,
Inv_Extra_Data AS IE,
Inv_Master AS IM,
ML_HCC AS M
WHERE
A.Status = 'Approval' AND
A.Invoice_no != 0 AND
IM.Status = 'Appr' AND
DueDate <= CONVERT(datetime, CONVERT(int, GETDATE()))
GO