SQL Error (Missing Operator) In query operation error [duplicate] - sql

This question already has answers here:
SQL multiple join statement
(3 answers)
Closed 3 years ago.
I am building an application and using MS Access as database(Normally I don't use MS Access but the client needs service-less database). Anyways, I have multiple tables and using joins, I am trying to acquire output, here is the query
SELECT tblSalesDetail.Sales_Details_ID, tblProduct.Product_Name,
tblSalesDetail.Rate, tblSalesDetail.Quantity, tblSalesDetail.TaxableAmount,
tblSalesDetail.TaxableAmount + tblSalesDetail.CGST_Amt +
tblSalesDetail.SGST_Amt + tblSalesDetail.IGST_Amt AS TotalAmt
FROM tblSalesMain
INNER JOIN tblSalesDetail
ON tblSalesMain.Sales_Main_ID = tblSalesDetail.Sales_Main_ID
INNER JOIN tblProduct
ON tblSalesDetail.Product_ID = tblProduct.Product_ID
WHERE tblSalesMain.Sales_Main_ID=1
This query works perfectly in SQL Server but having the following error when trying to run in MS Access with text selected at _Name at tblProduct.Product_Name in the first line.
I tried by changing or removing that column, but it's not working.
I tried StackOverflow answers posted but none of them worked by the way. So it's not like I am directly posting a question here without trying to solve this.
I know this might be a simple problem but I am stuck. Let me know workaround this.
I know this is off the above topic but can anyone suggest me good service-less, localdb (not mdf based SQL Db) for visual studio?
Regards

MS Access is quite finicky about syntax. Try this:
SELECT tblSalesDetail.Sales_Details_ID, tblProduct.Product_Name, tblSalesDetail.Rate,
tblSalesDetail.Quantity, tblSalesDetail.TaxableAmount,
(tblSalesDetail.TaxableAmount + tblSalesDetail.CGST_Amt + tblSalesDetail.SGST_Amt + tblSalesDetail.IGST_Amt) AS TotalAmt
FROM (tblSalesMain INNER JOIN
tblSalesDetail
ON tblSalesMain.Sales_Main_ID = tblSalesDetail.Sales_Main_ID
) INNER JOIN
tblProduct
ON tblSalesDetail.Product_ID = tblProduct.Product_ID WHERE tblSalesMain.Sales_Main_ID = 1

Related

SQL server 2000 internal error 8624 in the same code that have been ran for 10 years

I have a legacy SQL server 2000 database running at my office and recently the 10-year code that had had to work for 10 years. Now having the weird problem.
The code is really simple, it is the update statement for 3 fields. However, now when I tried to update one of the fields(ard.Applbatnbr) in this query now, I got the internal error 8624. (Just to be clear again, this code was running for 10 years with no problem)
UPDATE Ard
SET ard.Applbatnbr ='',ard.ApplAmt=0,ard.CuryApplamt=0
FROM wrkrelease w INNER JOIN batch b
ON b.batnbr = w.batnbr
INNER JOIN ardoc ard
ON ard.Applbatnbr = b.batnbr
WHERE b.Module='AR' AND w.Module='AR'
AND useraddress =#useraddress
AND b.status ='I'
AND b.editscrnnbr ='08030'
This code will return the error message 'Internal SQL server error'
However, when I tried to update only another 2 fields by removing the problem field(ard.Applbatnbr) I could process the update with no error.
UPDATE Ard
SET ard.ApplAmt=0,ard.CuryApplamt=0
FROM wrkrelease w INNER JOIN batch b
ON b.batnbr = w.batnbr
INNER JOIN ardoc ard
ON ard.Applbatnbr = b.batnbr
WHERE b.Module='AR' AND w.Module='AR'
AND useraddress =#useraddress
AND b.status ='I'
AND b.editscrnnbr ='08030'
I tried to update this field "ard.Applbatnbr" with another query in the table directly with no join with another 2 tables. like the example below, I did not get any error as well.
update ardoc set ard.Applbatnbr = '' where batnbr = 'xxxxx'
The internal error will be shown whenever I have this field "ard.Applbatnbr" update and join those 3 (wrkrelease, batch, ardoc) tables at the same time.
I also tried to run this query in another database that contains the same table structure and the query will work just fine. So I am completely lost. Is there anything I miss? Please help.

Hung Up on Concatenation Code

I am trying to combine two tables, S&P2 and Foundation, so that I can transfer information from corresponding rows in S&P2.Tic into Foundation.Ticker.
I created this code; however, no matter how I alter the code SQL always returns the Error Code 1054: Unknown Column/Field. This field is always S&P2. If this error does not pop up, SQL will just continually run.
USE nasdaqProj;
SELECT `S&P2`.`fyear`
FROM `nasdaqProj`.`S&P2`;
select * from Foundation;
SELECT `S&P2`.`conm` As sconm, `S&P2`.`tic` as 'ticker'
from nasdaqProj.`S&P2`
left outer join Foundation
ON `S&P2`.conm LIKE CONCAT (Foundation.comnm,'%')
and `S&P2`.fyear = Foundation.year
UNION
SELECT `S&P2`.`conm` As sconm, `S&P2`.`tic` as ticker
from nasdaqProj.`S&P2`
right outer join Foundation
ON `S&P2`.conm LIKE CONCAT (Foundation.comnm,'%')
and `S&P2`.fyear = Foundation.year;
I have been stuck on this for a while, and after reading the other error code 1054 question answers I was still unable to apply the solutions to my code.
Have you tried breaking the query into as small statements as possible? Try running each side of the union statement separately.

MS Access 2016 Error: "Multi-level group by not allowed"

i'm stuck at another point in my little Access 2016 Database. My code looks like the following and i know it probably isn't the cleanest solution but i'm kinda new to this and i tried to educate myself and get some help here already.
I'm trying to play around with the reports now a little bit and i am using this test query which returns all entries of two tables joined together.
As far as i could find out I have this one subquery included that returns the prvious day inventory for each record and that is most likely the cause of my error. I found a possible solution with adding SELECT * FROM at the beginning of my code but i get a Syntax error when i do that and i'm not sure how to solve this problem.
here's my code
SELECT Stations.StationName, Product.ProductName, GasInventoryTransactions.TransactionDate, (SELECT TOP 1 Dupe.ActualInventory FROM GasInventory AS Dupe WHERE Dupe.StationID = Stations.StationID AND Dupe.ProductID = Product.ProductID AND Dupe.InventoryDate < GasInventory.InventoryDate ORDER BY Dupe.InventoryDate DESC) AS PreviousDayInventory, GasInventory.ActualInventory, GasInventoryTransactions.GasSales, GasInventoryTransactions.GasDelivery, [PreviousDayInventory]+[GasDelivery]-[GasSales] AS BookBalance, GasInventory.ActualInventory, [ActualInventory]-[BookBalance] AS OverShort
FROM (Stations INNER JOIN (Product INNER JOIN GasInventory ON Product.[ProductID] = GasInventory.[ProductID]) ON Stations.[StationID] = GasInventory.[StationID]) INNER JOIN GasInventoryTransactions ON GasInventory.[InventoryDate] = GasInventoryTransactions.[TransactionDate];
thanks for your help!

SQL Query - MS SCCM

I´m trying to make a report in MS SCCM where I can check the distribution status of Software XY. Now there can be more parts of one software installed (for example XYa, XYb....) but I only want to list the pc once in my report.
I tried this adding the keyword distinct but nothing changes. Can you help me?
Here´s my query:
select distinct SMS_R_System.Name0,__System_ADD_REMOVE_PROGRAMS0.DisplayName00,__System_ADD_REMOVE_PROGRAMS0.Version00 from vSMS_R_System AS SMS_R_System INNER JOIN Add_Remove_Programs_DATA AS __System_ADD_REMOVE_PROGRAMS0 ON __System_ADD_REMOVE_PROGRAMS0.MachineID = SMS_R_System.ItemKey INNER JOIN _RES_COLL_SMS00001 AS SMS_CM_RES_COLL_SMS00001 ON SMS_CM_RES_COLL_SMS00001.MachineID = SMS_R_System.ItemKey where __System_ADD_REMOVE_PROGRAMS0.DisplayName00 like N'%XY%'
You'll get a row returned for each different application name and version because you're including DisplayName00 and Version00 in your SELECT statement. If you just have the system name in the SELECT then the distinct will work as intended.

Is it possible to make a recursive SQL query - with HP Quality Center?

This question has already been asked in stackoverflow and elsewhere:
Is it possible to make a recursive SQL query ?
Requêtes récursives avec les CTE - Exemples avec SQLServer 2003
But I would like to make this work for a report query in HP Quality-Center 10.
Anybody with insights into such technicalities?
A simple check:
with t1 (parent, child) as
(select * from all_lists t where t.al_father_id = '2') select * from t1
QC reports "Quality Center cannot run the query because it contains invalid statements".
Whereas with the following intentional typo
select * from all_lists t wher t.al_father_id = '2'
QC reports "The SQL query ... has failed to run, with the following error: Failed SQL ... [Mercury][Oracle JDBC Driver][Oracle]ORA-00933: SQL command not properly ended."
So I guess it answers two questions:
the server is Oracle (though it does not give the version)
with is not allowed through the QC interface
Ok, got it:
select SYS_CONNECT_BY_PATH (al_description,' :: ')
from all_lists
start with al_father_id = '2'
connect by prior al_item_id = al_father_id
This is the solution to my query. Thanks to a_horse_with_a_name for comments that motivated me to search deeper.
Fab.
I'm still open to comments for improvement or further trips and tricks of the trade - such as: where can I find a reference for the CONNECT BY related functions like SYS_CONNECT_BY_PATH. I'm sure it has a few friends I'd be keen to learn about.