Updating in SQL Problems - sql

Can anyone help me with this problem? I'm trying to update my database using the SQL below, but when I run it this message comes out:
The multi-part identifier "try_subject.subject_code" could not be bound.
UPDATE try_schoolyear
SET school_year= '" & drpcurriculumyear.SelectedItem.Text & "'
FROM try_schoolyear
INNER JOIN try_yearlvl on
try_schoolyear.schoolyearID=try_yearlvl.schoolyearId
WHERE try_subject.subject_code= '" & txtsearchcourse.Text & "'

the table try_subject won't be joined in your query. And that is why the engine can't find it.

Related

MS Access sql - Update query syntax

Seems a small issue with an sql update query. But I can not get my head around this issue. Not very much acquainted with sql.
Based on a selection, selected rows from a table (7DARphases) are copied and inserted to another table (7tblDAR). And the Project ID (PRJID column) for all the inserted rows should be updated with a fixed value (PID) taken from the form.
Issue is: I am facing syntax issue in the part where the fixed value needs to be inserted in the PRJID column of added rows.
Code is:
Set dbs = CurrentDb
PID = Me.PRJID.Value
sqlstr = "INSERT INTO 7tblDAR (Phase, Deliverable, Link_PIM_temp, Link_PIM_WB, Description, Accept_criteria, Deliv_type, TollgateID, Workstream, Accountable, ClientRACI) SELECT [7DARphases].Phase, [7DARphases].Deliverable, [7DARphases].Link_PIM_temp, [7DARphases].Link_PIM_WB, [7DARphases].Description, [7DARphases].Accept_criteria, [7DARphases].Deliv_type, [7DARphases].TollgateID, [7DARphases].Workstream, [7DARphases].Accountable, [7DARphases].ClientRACI FROM 7DARphases WHERE ((([7DARphases].SolType) Like '*2PP*')) ORDER BY [7DARphases].Phase, [7DARphases].Deliverable;"
sqlUpdt = "update 7tblDAR set PRJID = '" & Me.PRJID.Value & "' from 7tblDAR where tblDAR.PRJID = """""
dbs.Execute sqlstr, dbFailOnError
dbs.Execute sqlUpdt, dbFailOnError
The 'sqlstr' works fine and inserts rows.
But 'sqlUpdt' gives error:
"Run-time error 3075: Syntax error (missing operator) in query expression ..."
Can you please help me out with this.
Plus, if possible, can you suggest to perform this action in one query itself.
Why not put the value in when you insert the values?
sqlstr = "INSERT INTO 7tblDAR (Phase, Deliverable, Link_PIM_temp, Link_PIM_WB, Description, Accept_criteria, Deliv_type, TollgateID, Workstream, Accountable, ClientRACI, PRJID)
SELECT . . .,
'" & Me.PRJID.Value & "'
WHERE [7DARphases].SolType Like '*2PP*')
ORDER BY [7DARphases].Phase, [7DARphases].Deliverable;"
This saves the trouble of having to update it later.

How do I copy data from a table in an Access DB on a server to another Access DB

I know that there is a similar question already posed. Since the answers are more than 6 years old, I started a new thread.
I have a Access DB and a copy of that DB. The plan is to write data to the copy and then automatically the new data to the original. So basically both DBs are the same.
I found and answer here: How Do I Copy a table from one Access DB to another Access DB. Now I want to adapt this to my purpose but I fail.
I have attached the SQL string
strSQL = "INSERT INTO [maintblKeyFinancials].* " & _
"IN '" & destination_DB & "' " & _
"SELECT * FROM [maintblKeyFinancials] " & _
" WHERE [Company_ID] = " & identifier & _
" AND [Reference_year] = " & Chr$(34) & Year & Chr$(34) & ";"
Yes, [Reference_year] is a string. I also attached the Output
INSERT INTO [maintblKeyFinancials].* IN 'C:\destination.accdb'
SELECT * FROM [maintblKeyFinancials] IN 'C:\source.accdb'
WHERE [Company_ID] = 899 AND [Reference_year] = "2015";
When I execute the string, I get "syntax error in query. incomplete query clause". And I don't know what to correct. Hope you can help me. Thx!
INSERT INTO [maintblKeyFinancials].*
Remove the .* at the end, this gives the syntax error. It's either
INSERT INTO [maintblKeyFinancials] (column1, column2)
SELECT column1, column2 FROM ...
or if the columns are completely identical
INSERT INTO [maintblKeyFinancials]
SELECT * FROM ...
write [YourServer].[yourSchema].[YourTable]
SELECT * FROM [YourServer].[YourSchema].[maintblKeyFinancials]

VB.net Get Primary key of row that has just been updated

I have an update statement and i wanted to know how i could get the primary key of the row i just updated.
SELECT ##identity
I tried this but it didn't work.
I keep on getting 0.
But my update statement could be the problem aswell because in not sure about it either.
UPDATE payment INNER JOIN booking SET hire_cost=" & cost(1) & ",additional_cost=" & cost(0) & ",total_cost=" & cost(2) & ",Deposit=" & Math.Round(cost(2) / 4) & " WHERE booking.bookingID='" & y & "' AND payment.PaymentID=booking.PaymentID
Please help!
You will need to specify your column in the database as an identity column for it to return anything other than 0

Error in SQL query expression

I´m trying to run the following SQL code on access 2010, but it returns syntax error in query expression. Any ideas what could be causing it?
Thanks in advance.
DELETE FROM Trn_done
WHERE (Trn_done.training =
SELECT Training
FROM Trainings
WHERE (Trainings.Area = '" & Area & "'))
The bracket should be before the nested SQL as mentioned below
DELETE FROM Trn_done
WHERE Trn_done.training IN (
SELECT Training
FROM Trainings
WHERE (Trainings.Area = '" & Area & "')
)
You shouldn't EQUAL a select statement, lest multiple rows in your select cause your code to break. Try this instead:
DELETE td
from Trn_done td
inner join Trainings t
on td.training = t.training
WHERE t.Area = '" & Area & "'

Data type mismatch in criteria expression for Access AutoNumber

RentReturnCommand.CommandText = "update CustomerOrder set Status = '" &_ OrderStatusComboBox.Text & "' WHERE CID = " & CIDTextBox.Text & " AND CompID = " &_ CompIDText.Text
RentReturnCommand.ExecuteNonQuery()
RentReturnCommand.ExecuteNonQuery() constantly shows up as the error.
I've looked up all possible solutions to change this, but nothing works. My CID is listed in Access Database as an AutoNumber.
I know AutoNumber tends to cause a problem with this type of SQL involved, but I really need to query that in my program.
If I type "fred" in your textbox, this error will take place. Two things that will help you are validating all user input and using query parameters.