I'm getting an error message of "ORA-00936: missing expression" at the very start of line 2 at SELECT. I've looked over the data a countless number of times but can't seem to notice where i'm going wrong. I have a feeling it will be something extremely obvious! Any help would be great
Insert into EmployeeTable values
SELECT Name('Mrs','Alison','Smith'),
Address('23 Dart Grove', 'Edinburgh', 'EH10 5TT'),
Phone('01312125555', '07705623443','07907812345'),
'N1001',
ref(b),
'null',
'101',
'Head',
'50000',
'01-FEB-92'
from branchtable b
where b.bID = '901';
Remove the VALUES:
Insert into EmployeeTable
SELECT ...
But I fear that this might not be the only issue...
Related
I was hoping someone could point me in the right direction for troubleshooting.
I work for a small company and we are building a new application. I have the insert statement below (with selected static values for testing) that was working until this morning when we started getting error messages from it (we changed nothing about this table).
INSERT INTO t_el_powertrain
(
[pt_id]
,[el_id]
,[segment_id]
,[continuous_hp]
,[intermittent_hp]
,[torque]
,[torque_rpm]
,[eop]
,[checked_out]
,[create_date]
,[created_by]
,[update_date]
,[updated_by]
,[captive]
)
SELECT 1, --pt_id
100000, --el_id
5 , --segment_id
5.00, --continuous_hp
5.00, --intermittent_hp
5.00, --torque
5, --torque_rpm
5, --eop
0, --checked_out
GetDate(), --create_date
5 , --created_by
GetDate(), --update_date
5, --updated_by
10
Error message:
Here is a screenshot of the table structure (I refreshed the connection right before)
It seems pretty clear to me that there should be no issues with the insert statement below. Does anyone have any idea why I might be getting an error here?
Thanks for the help!
EDIT: added picture of the error message
UPDATE:
Thanks to a quick response from Martin Smith, I realized that I totally overlooked what DB object was throwing the error.
I forgot to update our history mirror table when I added a column a while back.
Solved. Thanks again.
I am a relative beginner in SQL (Learned and forgotten many times) and entirely self taught so please excuse my likely lack of proper terminology. I made a query that pulls items that have been returned, each items' row has a return code. Here is a result sample:
In the final report(Created with Visual Studio), I would like to be able to have a count of returns by return type but I would need to consolidate the 40 or so return codes into 4 or 5 return type groups. So RET_CODE values ) and . are both product quality issues and would count in the "Product Quality" row.
I could use some help with what the best way to accomplish this would be.
Thank You
Andrew
The bad way!
You could do this by creating the grouping within your SQL statement with something like
SELECT
*,
CASE
WHEN RET_CODE IN ('.', ')') THEN 'Quality Error'
WHEN RET_CODE IN ('X', 'Y', 'Z') THEN 'Some Other error'
ELSE [Desc1]
END AS GroupDescription
FROM myTable
The problem with this approach is that you have to keep repeating it every time you want to something similar.
The better option. (but not perfect!)
Assuming you do not already have such a table...
Create a table that contains the grouping. You can use this in the future whenever you need to do this kind of thing.
For example.
CREATE TABLE dbo.MyErrorGroupTable (RET_CODE varchar(10), GroupDescription varchar(50))
INSERT INTO dbo.MyErrorGroupTable VALUES
('.', 'Quality Error'),
(')', 'Quality Error'),
('X', 'Some Other Error'),
('Y', 'Some Other Error'),
('.', 'Some Other Error'),
('P', 'UPS Error'),
('A', 'PAck/Pick Error')
etc....
Then you can simply join to this table and use the GroupDescription in your report
e.g.
SELECT
a.*, b.GroupDescription
FROM myTable a
JOIN MyErrorGroupTable b ON a.RET_CODE = b.RET_CODE
Hope this helps...
You're looking for the GROUP BY clause.
I'm getting an incorrect syntax error when I try to execute this query in t-sql. I'd appreciate any help - I believe the issue is on, or around the ROUND statement.
SELECT
EMPL.employeeid as KEmplID,
EMPL.PERSONNUM as EmployeeNumber,
EMPL.PERSONFULLNAME as FullName,
....
FROM
VP_EMPLOYEE as EMPL,
VP_PERSON as PRSN,
(
SELECT
TLS.employeeid as EMPLID,
TLS.applydate as APPLYDATE,
ROUND((SUM(CONVERT(FLOAT,TLS.timeinseconds)) /60/60,1)) AS ElapsedHrs
FROM
VP_TOTALS as TLS,
VP_PAYCODE as PAYCODE
....
I am just not quite sure where my issue stems - again, I think it is the round statement but I could be wrong. I will appreciate any and all help - or suggestions - to make this more efficient or help with the rounding, conversion and sum of the data.
Incorrect:
ROUND((SUM(CONVERT(FLOAT,TLS.timeinseconds)) /60/60,1)) AS ElapsedHrs
Corrected (parenthesis placement):
ROUND((SUM(CONVERT(FLOAT,TLS.timeinseconds)) /60/60),1) AS ElapsedHrs
^
I'm trying to display all such rows of a table STUDENTS which have a value of an attribute, such as COURSE IN a set of given values e.g. 'MS', 'PhD'.
I get the values in the students_controller.rb file using params. I tried to run an Active Record query using where to do the job:
#all_courses = ['MS', 'PhD', 'BA', 'MSc']
#students = Student.where("course IN :courses" , {:courses => params.has_key?(:courses) ? params[:courses].keys : #all_courses})
But I get the following error:
SQLite3::SQLException: near ",": syntax error: SELECT "students".* FROM "students" WHERE (course IN 'MS', 'PhD', 'BA', 'MSc')
I think the error might be due to the absence of ; at the end of the SQL query generated by Active Record, but I cannot do anything to get that semicolon at the end.
You need to use parentheses: "course IN (:courses)"
I'm using SQLAlchemy 0.5.8, and seeing this error:
ProgrammingError: (ProgrammingError) can't adapt 'INSERT INTO enumeration_value (id,
key_id, code, name, notes) VALUES (%(id)s, %(key_id)s, %(code)s, %(name)s, %(notes)s)'
{'key_id': 'aac6fc29-4ccd-4fe4-9118-cfbbd04449fe', 'notes': '', 'code': (u'Barnet',),
'id': 'd0540c97-882e-4a5b-bf14-b3ebcfeea051', 'name': (u'Barnet',)}
But a direct SQL insert with the values from the error seems to work just fine:
=> INSERT INTO enumeration_value (id, key_id, code, name, notes)
VALUES ('d0540c97-882e-4a5b-bf14-b3ebcfeea051', 'aac6fc29-4ccd-4fe4-9118-cfbbd04449fe',
'Barnet', 'Barnet', '');
INSERT 0 1
If the direct SQL works OK, how can I start to debug this?
Incidentally, the line that's throwing the error doesn't seem to have an INSERT statement in it at all, so I am a bit confused:
File "----barnet.py", line 117, in load_file
instance = model.Session.query(model.EnumerationValue).filter_by(key=key_barnet_level_2, code=level_2).all()
Do SQLAlchemy filter statements generate INSERT commands, or does this just happen to be the last line before things start to go wrong?
Figured it out - the problem was actually a syntax error a few lines higher up, with a rogue comma:
key_from = code,
Sorry if I wasted anyone's time. Please close the question.