Question : Delphi SQL Query Help

Hi Guys

I am currently using excel with an odbc datasource to query certain stock lines from our sql server database using the below code

SELECT StockItem.Code, RTLPrdHierarchy.Description, RTLPrdHierarchy_2.HierNodeName, BinItem.BinName, Warehouse.Description, (BinItem.ConfirmedQtyInStock+BinItem.UnconfirmedQtyInStock), StockItem.AverageBuyingPrice, (BinItem.ConfirmedQtyInStock+BinItem.UnconfirmedQtyInStock)*StockItem.AverageBuyingPrice, StockItem.Manufacturer, BinItem.ConfirmedQtyInStock+BinItem.UnconfirmedQtyInStock-BinItem.QuantityAllocatedSOP-BinItem.QuantityAllocatedStock

FROM dbo.BinItem BinItem, dbo.RTLPrdHierarchy RTLPrdHierarchy, dbo.RTLPrdHierarchy RTLPrdHierarchy_1, dbo.RTLPrdHierarchy RTLPrdHierarchy_2, dbo.RTLStockItem RTLStockItem, dbo.StockItem StockItem, dbo.Warehouse Warehouse, WarehouseItem WarehouseItem

WHERE StockItem.Code = RTLPrdHierarchy.HierNodeName AND RTLPrdHierarchy.ParentPrdHierNodeId = RTLStockItem.PrdHierNodeId AND RTLStockItem.PrdHierNodeId = RTLPrdHierarchy_1.PrdHierNodeId AND BinItem.ItemID = StockItem.ItemID AND WarehouseItem.WarehouseItemID = BinItem.WarehouseItemID AND Warehouse.WarehouseID = WarehouseItem.WarehouseID AND RTLPrdHierarchy_1.ParentPrdHierNodeId = RTLPrdHierarchy_2.PrdHierNodeId AND (((BinItem.ConfirmedQtyInStock+BinItem.UnconfirmedQtyInStock)<>$0) AND (RTLStockItem.Code Like (?+'%')) AND (StockItem.Manufacturer Like (?+'%')))
ORDER BY StockItem.Code

I am trying to move the query over into delphi but i keep getting errors saying "missing right quote" . Here is the code i have tried so far.

'SELECT StockItem.Code, RTLPrdHierarchy.Description, RTLPrdHierarchy_2.HierNodeName, BinItem.BinName, Warehouse.Description, (BinItem.ConfirmedQtyInStock+BinItem.UnconfirmedQtyInStock), StockItem.AverageBuyingPrice, (BinItem.ConfirmedQtyInStock+BinItem.UnconfirmedQtyInStock)*StockItem.AverageBuyingPrice, StockItem.Manufacturer, BinItem.ConfirmedQtyInStock+BinItem.UnconfirmedQtyInStock-BinItem.QuantityAllocatedSOP-BinItem.QuantityAllocatedStock FROM dbo.BinItem BinItem, dbo.RTLPrdHierarchy RTLPrdHierarchy, dbo.RTLPrdHierarchy RTLPrdHierarchy_1, dbo.RTLPrdHierarchy RTLPrdHierarchy_2, dbo.RTLStockItem RTLStockItem, dbo.StockItem StockItem, dbo.Warehouse Warehouse, dbo.WarehouseItem WarehouseItem '+
'WHERE StockItem.Code=RTLPrdHierarchy.HierNodeName AND RTLPrdHierarchy.ParentPrdHierNodeId=RTLStockItem.PrdHierNodeId AND RTLStockItem.PrdHierNodeId=RTLPrdHierarchy_1.PrdHierNodeId AND BinItem.ItemID=StockItem.ItemID AND WarehouseItem.WarehouseItemID=BinItem.WarehouseItemID AND Warehouse.WarehouseID=WarehouseItem.WarehouseID AND RTLPrdHierarchy_1.ParentPrdHierNodeId=RTLPrdHierarchy_2.PrdHierNodeId AND (((BinItem.ConfirmedQtyInStock+BinItem.UnconfirmedQtyInStock)<>$0) AND RTLStockitem.code LIKE (''%' + edit1.text + '%'') ORDER BY StockItem.Code';

Could somebody please help me change this to a friendly delphi query.

Thank you in advance

Answer : Delphi SQL Query Help

You have an extra opening bracket on the line
AND (((BinItem.ConfirmedQtyInStock+BinItem.UnconfirmedQtyInStock)<>$0)

should be
AND ((BinItem.ConfirmedQtyInStock+BinItem.UnconfirmedQtyInStock)<>$0)
Random Solutions  
 
programming4us programming4us