有效 SQL 上的 Visual Studio 错误
我在 Visual Studio 中遇到一个恼人的错误,因为 SQL 执行得很好。
SELECT InvoiceLines.LineID,
InvoiceLines.InvoiceID,
InvoiceLines.Text,
InvoiceLines.Rate,
InvoiceLines.Count,
InvoiceLines.Rate * InvoiceLines.Count AS LineTotal,
((InvoiceLines.Rate * InvoiceLines.Count) * (1 + Invoices.VatRate / 100)) * (1 - CAST(Invoices.Discount AS money) * InvoiceLines.ApplyDiscount / 100) AS LineTotalIncVat, InvoiceLines.ApplyDiscount
FROM InvoiceLines
LEFT JOIN Invoices ON Invoices.InvoiceID = InvoiceLines.InvoiceID
LineTotalIncVat 试图做的是计算发票项目的总额,同时添加增值税并减去折扣,是的,可能更好地在代码中执行此操作(如果可以的话)
视觉工作室给出的错误是:
解析查询时出错 [令牌行号 =1,令牌行偏移量 =14,错误令牌 = InvoiceLines]
即使它将在查询生成器中验证和执行而不会出现问题...
I'm getting an annoying error in visual studio for SQL that executes fine.
SELECT InvoiceLines.LineID,
InvoiceLines.InvoiceID,
InvoiceLines.Text,
InvoiceLines.Rate,
InvoiceLines.Count,
InvoiceLines.Rate * InvoiceLines.Count AS LineTotal,
((InvoiceLines.Rate * InvoiceLines.Count) * (1 + Invoices.VatRate / 100)) * (1 - CAST(Invoices.Discount AS money) * InvoiceLines.ApplyDiscount / 100) AS LineTotalIncVat, InvoiceLines.ApplyDiscount
FROM InvoiceLines
LEFT JOIN Invoices ON Invoices.InvoiceID = InvoiceLines.InvoiceID
What LineTotalIncVat is trying to do is compute the total for the invoice item while adding the vat and subtracting the discount, and yes, probably better to do this in code (would if I could)
The error visual studio gives is:
There was an error parsing the query [token line number =1, token line offset =14, token in error = InvoiceLines]
Even though it will validate and execute without a problem in the query builder...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试将表和列名称括起来,解析
InvoiceLines.Count
可能会遇到问题,因为Count
是保留字。尝试[InvoiceLines].[Count]
。Try bracketing the table and column names, it may be having trouble parsing
InvoiceLines.Count
becauseCount
is a reserved word. Try[InvoiceLines].[Count]
.已解决
从数据集中删除该表并使用完全相同的 SQL 再次添加它。
多么奇怪……虽然我已经不是第一次这么做了。
Solved
Deleted the table from the dataset and added it again with exactly the same SQL.
How strange... although not the first time I've had to do this.