I'm having trouble with what should seemingly be a fairly straightforward SQL query. The code below:
SELECT lines.ItemID, lines.TransCode, lines.Qty, headers.InvoiceID, items.ItemID, items.Description, items.Misc2, items.Misc3, items.Location
FROM InvLines lines
JOIN InvHeaders headers ON lines.ParentRecordID = headers.RecordID
JOIN Items items ON lines.ItemID = items.ItemID
WHERE headers.CustomerID = "LOST" AND headers.InvoiceID NOT LIKE "K%" AND lines.TransCode <> "T";
Causes the error message:
ASA Error -143: Column 'LOST' not found [SQL State=52003, DB Errorcode=207]
Obviously "LOST" is the condition I am selecting for, so I don't understand why it is getting treated as a column. I can't seem to find any information on this error caused by a similar situation.
I'm using SQLWorkbench/J to connect to the db and make this query.
Apologies for any necessary information left out or poor formatting, I am new at this. Please let me know and I will correct it.
Related
im trying to join data together using the join function on SQL and every time i run my query it shows error and the error says according to the data im using right now, it says 'bikeshare_trips' is not qualified with the dataset (e.g data table )
i checked for the data in the dataset and its there so i dont really understand what the error mean. and also check for any mistakes in my query and run it again but still the same result. and the link to my query is gonna be placed in case anyone wants to check it out. https://console.cloud.google.com/bigquery?sq=740828604161:fd77df6d30144ae5ab39070c0d68d6a1
the error actually tells you your mistake. You need to specify the complete dataset name, i.e.
bigquery-public-data.austin_bikeshare.bikeshare_trips
Looks like you forgot to mention bigquery-public-data.austin_bikeshare. to the trips table. Here is the query running with the complete dataset mentioned.
SELECT bs.name, bs.status, bs.modified_date,
bt.trip_id, bt.subscriber_type, --bt.biked,
bt.duration_minutes
FROM `bigquery-public-data.austin_bikeshare.bikeshare_stations` AS bs
JOIN `bigquery-public-data.austin_bikeshare.bikeshare_trips` AS bt
ON bs.station_id = bt.start_station_id
I have the following queries ...
Query #1
SELECT aa.DocNum, b.QualityClass
FROM dbo_TransferHistory AS aa LEFT JOIN PCQualityClass AS bb ON aa.DocNum = bb.DocumentNum
WHERE (((aa.DocNum)=[Enter Doc Num]));
Query #2
SELECT aa.DocNum, bb.QualityClass, cc.BldgCond
FROM (dbo_TransferHistory AS aa LEFT JOIN PCQualityClass AS bb ON aa.DocNum = bb.DocumentNum)
LEFT JOIN PCBldgCond AS cc ON aa.DocNum = cc.DocumentNum
WHERE (((aa.DocNum)=[Enter Doc Num]));
dbo_TransferHistory is an table I access through an ODBC connector.
PCQualityClass and PCBldgCond are two queries that are based off another ODBC table. Both of these queries have only the two respective fields referenced in the main query.
DocNum and DocumentNum are the same type ("Short Text" and a length of 12) and while I would like to make the names the same, I cannot.
When the query is run, an Inputbox pops up and [Enter Doc Num] is replaced with the Document Number I want the data for.
The queries were created in Access using the Create Query tool.
The problem is that while Query #1 will work, Query #2 causes the error "Invalid Operation".
Changing to inner joins will allow Query #2 to function but will cause issues as there are times that one or both of the two sub queries do not have data but I still need the data from the primary table.
Please help, I am at my wits end as to why this is not working. Is this an Access 2013 bug that will not allow for two Left Joins in the same query or something else I am missing?
The SQL looks like it should work, so the problem is probably the combination of the base queries plus the two left joins.
My general experience with Access queries on ODBC tables and with multiple outer joins is: even if you get them to work, they usually perform pretty badly.
So my suggestion is: Re-create the whole thing as view on SQL Server, and link that view. Then your Access query becomes something trivial like
SELECT * FROM dbo_ViewTransferHistory
WHERE DocNum=[Enter Doc Num]
Ok, so this is frustrating the absolute !##$% out of me. The syntax is correct and everything I see online says it should work. Out of pure frustration and some curiosity, I imported the ODBC tables into Access as local tables and changed the table references in the queries to use the local tables. OMG, now it works. Same data, same structure, different table type, and it !##$ing works. So it looks like the problem is in attempting to make multiple joins using ODBC. Unfortunately, I cannot create local tables from the ODBC every time this query gets run. Going to keep looking into this and see if I can find another workaround. Any other ideas?
Basically, Access will not allow multiple Outer Joins when using ODBC data sources. I am going to mark this as answered and rephrase the question in a new post.
Thank you.
I' not getting an error message but i seem to be only getting 5 results no matter what i choose, so this leaves me to beleive that there is something wrong with my SQL statement. I'm usint node.js tedious to connect to sql 2008 r2 database. Previous statements worked, but that was a simple select statement with the posting date where clause. I know there are spaces in my column names which is not good practice, but there is nothing i can do about that this because thedatabase is utilized by Navision. Normally there are no line breaks, i just did that to make it appear more orderly to you guys.
SELECT
TA.[Amount],
TA.[Posting Date],
TA.[Entry No_],
TA.[Document No_],
TB.[Salesperson Code]
FROM [ShowTex Belgie NV$G_L Entry] as TA
LEFT OUTER JOIN [ShowTex Belgie NV$Sales Invoice Header] as TB
ON TA.[Document No_]=TB.[No_]
WHERE TA.[Posting Date]>'05/01/2015'
AND TA.[Document Type]='2'
AND TA.[Gen_ Posting Type]='2'
Strangely Enough the SQL turns out not to be the issu. It is the conversion from JSON.stringify to JSON.parse. I was certain i had tested this successfully before. But perhaps i was negligent. Anyways My code looks like this. when i Console.log(retVal) the data still looks correct about 100 reccords as expected.
retVal = JSON.stringify({result:dataSet});
fn(retVal);
function fn(retVal){
var obj = JSON.parse(retVal);
for(var i = 0; i<Object.keys(obj.result[0]).length;i++){
console.log(obj.result[i]);
}
}
If i console.log(retVal) inside the fn function i still get my wall of text as expected. but within the FOR statement i only get the first 5 records. Hmm I bet I'm headbutting a rookie mistake at the moment. :/
Totally depends on what you want but here is a cheat sheet with venn diagrams. http://www.codeproject.com/KB/database/Visual_SQL_Joins/Visual_SQL_JOINS_orig.jpg so that it might be more logically to see what you are doing.
Wow, i found my problem. It's really embarrassing, the SQL was correct, i was counting the number of columns in my json file, this returned 5 each time. Sorry for Wasting people's time. Thank you so much for your feedback. It was helpfull in a sense that i was fixated on getting my sql statement wrong because I'm not good at those so your feedback was helpfull. It never occurred to me that I could still be running into rookie mistakes likes this.
i<Object.keys(obj.result[0]).length
needs to be
i<Object.keys(obj.result).length
I have the following SQL:
select <misc things>
from pluspbillline
left outer join workorder
on workorder.siteid=pluspbillline.siteid
and workorder.wonum = pluspbillline.refwo
and workorder.orgid = pluspbillline.orgid
left outer join ticket
on ticket.ticketid = pluspbillline.ticketid
and ticket.class=pluspbillline.ticketclass
left outer join pluspsalesorder
on pluspsalesorder.salesordernum=pluspbillline.salesordernum
and pluspsalesorder.siteid=pluspbillline.siteid
In Oracle SQL Developer 4.0.0.13 (connected to a DB2 database), I get a squiggly line underneath the following italics: "from pluspbillline" and "left outer join workorder".
The warning says "pluspbillline is disconnected from the rest of the join graph". What does this mean?
I got this as well. I'm not exactly sure how to articulate it but the error seems to be based on the logical flow of the code.
Essentially because you mention the table pluspbillline before workorder I think it expects the join to be on pluspbillline.siteid=workorder.siteid etc.
It seems that the order of the conditions for joins should flow from the first identified tables to the latest ones. So the following should make it happy:
plusbillline to workorder on pluspbillline.siteid=workorder.siteid...
"" to ticket on pluspbillline.ticketid = ticket.ticketid...
"" to pluspsalesorder on pluspbillline.salesordernum = pluspsalesorder.salesordernum...
I don't believe this would change the work oracle does (assuming you don't use optimizer hints) so I'd only bother to change if you hate the squiggly lines.
I'm not sure what's causing Oracle SQL Developer to give the error. But I'm putting this comment here to format it properly.
A join graph might look something like this
pluspbillline ------+----< workorder
|
+----< ticket
|
+----< pluspsalesorder
The lines on the graph might be labeled with the join fields. But this gives you a basic idea.
I don't see any reason why you are getting this warning. A column name typo in your SQL perhaps? Or some quirk in Oracle's interface that it doesn't understand the DB2 metadata properly? I suggested trying IBM's tool to see if it's merely their program.
The issue is caused by the Oracle Procedure having the same named input parameter as the column on the table you are joining to.
i.e input parm named bank_nbr and a table BankDept.bank_nbr will cause the error if you have WHERE bank_nbr = BankDept.bank_nbr
I solved the issue by renaming the input parameter to in_bank_nbr and updating my where to read WHERE in_bank_nbr = BankDept.bank_nbr
I had the same message when hovering over the "LEFT" word, but the whole query ran without a problem. On the other hand, when I hovered over "WITH", I got a piece of advice about restructuring the whole query. So, that message about disconnection could be not a sign of an error, but a warning about a too complex sentence. SQLDeveloper's editor does not mention the level of the problem.
I'm performing a SQL query through hibernate, which looks like:
SELECT thi
FROM track_history_items thi
JOIN artists art
ON thi.artist_id = art.id
WHERE thi.type = "TrackBroadcast"
GROUP BY art.name
ORDER thi.createdAt DESC
but I'm getting the message that 'Node to traverse cannot be null!'. Anyone know what could be causing this?
--EDIT--
I'm pretty sure that this problem is being caused by the possibility of artist_id to be null. However, I can't prevent this, so can I just skip the rows track_history_item rows which have a null artist_id?
I have gotten that error only when using createQuery instead of createNamedQuery.
So when detecting this, hibernate throws the exception.
Query query = entityManager.createQuery("DS.findUser");
node to traverse cannot be null!
This is a generic Hibernate error message indicating a syntax problem in your query. As another example, forgetting to start a select clause with the word "SELECT" would yield the same error.
In this instance the syntax error is due to the on clause - HQL does not support them. Instead do a cross join like so:
FROM track_history_items thi, artists art
WHERE thi.type = "TrackBroadcast"
AND thi.artist_id = art.id
GROUP BY art.name
ORDER thi.createdAt DESC
I have come across this issue several times before as well and it has always been the case that the code was attempting to run a named query by calling createQuery instead of createNamedQuery, e.g. if you have a named query named "FIND_XXX" then the code would be calling entityManager.createQuery(FIND_XXX) which results in it trying to execute the String representing the name of the named query as if it was a standard dynamic query String (which is obviously a problem).
You can also get this error if you execute a query that has a syntax error, such as forgetting a comma in an update statement
update MyObject set field1=5 field2=4 WHERE id = 4
See how there is a missing comma between field1=5 and field2=4? You will get a node to traverse cannot be null error.
This error comes usually due to one of the most stupid reason that one would not have even imagined. If you dop copy-paste the query, some special characters get introduced and you start getting this error. Make sure you type the query manually and it will work fine. Atleast in my case it worked.
If you are using Hibernate 4 you should be calling:
Query query = session.getNamedQuery(Entity.NAMED_QUERY);
instead of
Query query = session.createQuery(Entity.NAMED_QUERY);
This happens because session.createQuery will try to create the query based on the string value of Entity.NAMED_QUERY for example:
String NAMED_QUERY = "Entity.namedQuery";
resulting in a incorrect HQL and raising a exception.