Неверный синтаксис рядом с ключевым словом "DECLARE" в представлении - PullRequest
0 голосов
/ 30 мая 2019

Может кто-нибудь подтвердить, пожалуйста, как избавиться от следующей ошибки.

DECLARE @StartDate DATETIME, @EndDate DATETIME
SET @StartDate = DATEADD(mm, DATEDIFF(mm, 0, getdate()) - 1, 0)
SET @EndDate = DATEADD(mm, 1, @StartDate)
SELECT        
dbo.General_Ledger_Detail.Accounting_ID,
dbo.General_Ledger_Detail.Cost_Centre,
dbo.General_Ledger_Detail.Product_ID, 

dbo.General_Ledger_Detail.Accounted_Amount AS Amount, 
dbo.General_Ledger_Detail.Account_Name, 
dbo.General_Ledger_Detail.Accounting_Date, 

dbo.Account_Codes_Sales_OPEX$.[Opex Type], 
dbo.LogSolOpexCC.Logistic_Solutions_Type

FROM            
dbo.General_Ledger_Detail 
INNER JOIN dbo.Account_Codes_Sales_OPEX$ 
ON dbo.General_Ledger_Detail.Accounting_ID = 
    dbo.Account_Codes_Sales_OPEX$.[Account Code] 
INNER JOIN dbo.LogSolOpexCC 
ON dbo.General_Ledger_Detail.Cost_Centre = dbo.LogSolOpexCC.Cost_Centre

GROUP BY dbo.General_Ledger_Detail.Accounting_ID, 
dbo.General_Ledger_Detail.Cost_Centre, 
dbo.General_Ledger_Detail.Product_ID, 

dbo.General_Ledger_Detail.Accounted_Amount, 
dbo.General_Ledger_Detail.Account_Name, 
dbo.General_Ledger_Detail.Accounting_Date, 

dbo.Account_Codes_Sales_OPEX$.[Opex Type],     
dbo.LogSolOpexCC.Logistic_Solutions_Type

HAVING (dbo.General_Ledger_Detail.Accounting_Date BETWEEN @startdate AND @enddate)

Ответы [ 2 ]

1 голос
/ 30 мая 2019

Невозможно передать параметры представлениям SQL Server.https://www.mssqltips.com/sqlservertip/5147/limitations-when-working-with-sql-server-views/

0 голосов
/ 30 мая 2019
SELECT        dbo.General_Ledger_Detail.Accounting_ID, dbo.General_Ledger_Detail.Cost_Centre, dbo.General_Ledger_Detail.Product_ID, 
                         dbo.General_Ledger_Detail.Accounted_Amount AS Amount, dbo.General_Ledger_Detail.Account_Name, dbo.General_Ledger_Detail.Accounting_Date, 
                         dbo.Account_Codes_Sales_OPEX$.[Opex Type], dbo.LogSolOpexCC.Logistic_Solutions_Type
FROM            dbo.General_Ledger_Detail INNER JOIN
                         dbo.Account_Codes_Sales_OPEX$ ON dbo.General_Ledger_Detail.Accounting_ID = dbo.Account_Codes_Sales_OPEX$.[Account Code] INNER JOIN
                         dbo.LogSolOpexCC ON dbo.General_Ledger_Detail.Cost_Centre = dbo.LogSolOpexCC.Cost_Centre
GROUP BY dbo.General_Ledger_Detail.Accounting_ID, dbo.General_Ledger_Detail.Cost_Centre, dbo.General_Ledger_Detail.Product_ID, 
                         dbo.General_Ledger_Detail.Accounted_Amount, dbo.General_Ledger_Detail.Account_Name, dbo.General_Ledger_Detail.Accounting_Date, 
                         dbo.Account_Codes_Sales_OPEX$.[Opex Type], dbo.LogSolOpexCC.Logistic_Solutions_Type
HAVING        (dbo.General_Ledger_Detail.Accounting_Date BETWEEN DATEADD(mm, DATEDIFF(mm, 0, GETDATE()) - 1, 0) AND DATEADD(mm, 1, GETDATE()))
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...