开发者

Visual Studio error on valid SQL

开发者 https://www.devze.com 2022-12-31 05:17 出处:网络
I\'m getting an annoying error in visual studio for SQL that executes fine. SELECT InvoiceLines.LineID,

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 an开发者_如何学运维d execute without a problem in the query builder...


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消