views:

44

answers:

2

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...

+3  A: 

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

Jamie Ide
+1 definitely worth trying
oedo
Also `Text` can be a reserved keyword. The set of reserved keywords depends on the database driver used.
Guffa
Didn't work, the query builder stripped them out :(
Sam
A: 

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.

Sam