Mohsin
Mohsin

Reputation: 902

Incorrect syntax near 'b'

I am facing an error while a query is executed:

Incorrect syntax near 'b'

Code:

using(var db = new GnpCoreDatabase())
            {
                var basket = db.Query<Basket>
("select p.product_tax,c.shipping_cost FROM dbo.Basket b 
join dbo.CompanyProducts cp b.CompanyProduct_Id = cp.Product_Id 
join dbo.products p on p.Product_Id = cp.Product_Id 
join dbo.Company c on c.company_Id = cp.Company_Id 
where b.Added_by =@0", 1).Select(x => new Basket() {
                Tax = x.Tax,
                ShippingCost = x.ShippingCost,
                IsSuccessfull = true
                }).SingleOrDefault();
                basket.Items = GetAllItems();
                return basket;
            }

I don't understand why this error is occurs. I run this query in the database and it produces results.

Upvotes: 0

Views: 2118

Answers (1)

Horia
Horia

Reputation: 1612

You're missing the ON keyword on first JOIN:

select  p.product_tax,c.shipping_cost 
FROM    dbo.Basket b 
        join dbo.CompanyProducts cp ON b.CompanyProduct_Id = cp.Product_Id 
        join dbo.products p on p.Product_Id = cp.Product_Id 
        join dbo.Company c on c.company_Id = cp.Company_Id 
where b.Added_by =@0

Upvotes: 2

Related Questions