有效 SQL 上的 Visual Studio 错误

发布于 2024-09-02 22:25:48 字数 790 浏览 5 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夏有森光若流苏 2024-09-09 22:25:49

尝试将表和列名称括起来,解析 InvoiceLines.Count 可能会遇到问题,因为 Count 是保留字。尝试[InvoiceLines].[Count]

Try bracketing the table and column names, it may be having trouble parsing InvoiceLines.Count because Count is a reserved word. Try [InvoiceLines].[Count].

毁我热情 2024-09-09 22:25:49

已解决

从数据集中删除该表并使用完全相同的 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文