Updating a Microsoft Access 2013 table with data from a pass-through query - sql

I am trying, unsuccessfully so far, to update records in a Microsoft Access 2013 table (called tbl_Data) with data from an AS400 table (LIBRARY.TABLE).
As you can see in my Access 2013 pass-through query below, I am trying to join the access table with the AS400 table using the Prefix & Number fields, and from there, update the access table with Name & Address information from the AS400 table.
Here is my latest attempt:
UPDATE
tbl_Data
SET
tbl_Data.FirstName = a.NINMFR,
tbl_Data.MiddleName = a.NINMMD,
tbl_Data.LastName = a.NINAML,
tbl_Data.BuildingNumber = a.NIBLNR,
tbl_Data.StreetName = a.NISTNM,
tbl_Data.AptSuite = a."NIAPT#",
tbl_Data.Address2 = a.NIADR2,
tbl_Data.City = a.NICITY,
tbl_Data.State = a.NISTAT,
tbl_Data.ZipCode = a.NIZIPC
INNER JOIN
LIBRARY.TABLE a
ON
tbl_Data.Prefix = a.NIPRFX,
tbl_Data.Number = a.NIPLNR;
When I run this query, I get an error that says:
OBDC--call failed.
[IBM][System i Access ODBC Driver][DB2 for i5/OS]SQL0199 - Keyword INNER not expected. Valid tokens: USE SKIP WAIT WITH WHERE. (#-199)
I would really appreciate any assistance, as I'm out of ideas.
Thanks!

That is Microsoft specific syntax for an update, it does not work on DB2. Try this:
UPDATE
tbl_Data
SET
(tbl_Data.FirstName,
tbl_Data.MiddleName,
tbl_Data.LastName,
tbl_Data.BuildingNumber,
tbl_Data.StreetName,
tbl_Data.AptSuite,
tbl_Data.Address2,
tbl_Data.City,
tbl_Data.State,
tbl_Data.ZipCode)
=
(SELECT
a.NINMFR,
a.NINMMD,
a.NINAML,
a.NIBLNR,
a.NISTNM,
a."NIAPT#",
a.NIADR2,
a.NICITY,
a.NISTAT,
a.NIZIPC
FROM
library.table a
WHERE
tbl_Data.Prefix = a.NIPRFX,
tbl_Data.Number = a.NIPLNR)
WHERE
EXISTS (
SELECT *
FROM
library.table a
WHERE
tbl_Data.Prefix = a.NIPRFX,
tbl_Data.Number = a.NIPLNR);

Related

SQL Update statement not working - SQL Server

I am trying to run the below sql statement (SQL Server), however getting the error
"FROM clause in UPDATE and DELETE statements cannot contain subquery sources or joins."
update fp
set fp.totalcapacity = hc.totalcapacity,
fp.sellablecapacity = hc.sellablecapacity
from [fact].[FinalPosition] fp
join fact.[HotelCapacity] hc
on fp.hotelkey = hc.hotelkey
and fp.staydate = hc.staydate
where fp.staydate = '2016-06-18'
I can't seem to understand why I am getting this error. Any idea?
I think the syntax you want is:
update fp
set totalcapacity = hc.totalcapacity,
sellablecapacity = hc.sellablecapacity
from fp join
fact.[HotelCapacity] hc
on fp.hotelkey = hc.hotelkey and fp.staydate = hc.staydate
where fp.staydate = '2016-06-18';
If you want fp to refer to an actual table, include that in the from clause and make the fp the alias for the table.

How to use SQL Task to update a table

I have this SQL to update modified records in my table. It runs in SSMS, but how do I implement this in SSIS package? I tried to use SQL task but it does not recognize the columns.
I can put a select within a data flow ole db source (sql command has select statement), derived column for my import date, then ole db destination to update the records - but what is the syntax of the sql command to update?
update nss.MKT_CUSTOM
set
[INSURED_NUMBER] = stg_MKT_CUSTOM.[INSURED_NUMBER]
,[SALES_AGENCY_NUMBER] = stg_MKT_CUSTOM.[SALES_AGENCY_NUMBER]
,[PRODUCT_CODE] = stg_MKT_CUSTOM.[PRODUCT_CODE]
,[INS_MKT_INFO_SRC_CREATE_DATE] = stg_MKT_CUSTOM.[INS_MKT_INFO_SRC_CREATE_DATE]
,[INS_MKT_INFO_SRC_CREATE_USER] = stg_MKT_CUSTOM.[INS_MKT_INFO_SRC_CREATE_USER]
,[MKT_INFO_SRC_CODE] = stg_MKT_CUSTOM.[MKT_INFO_SRC_CODE]
,[MKT_INFO_SRC_DESC_EN] = stg_MKT_CUSTOM.[MKT_INFO_SRC_DESC_EN]
,[MKT_INFO_SRC_DESC_FR] = stg_MKT_CUSTOM.[MKT_INFO_SRC_DESC_FR]
,[MKT_INFO_SRC_START_DATE] = stg_MKT_CUSTOM.[MKT_INFO_SRC_START_DATE]
,[MKT_INFO_SRC_END_DATE] = stg_MKT_CUSTOM.[MKT_INFO_SRC_END_DATE]
,[MKT_INFO_SRC_CREATE_DATE] = stg_MKT_CUSTOM.[MKT_INFO_SRC_CREATE_DATE]
,[MKT_INFO_SRC_MOD_DATE] = stg_MKT_CUSTOM.[MKT_INFO_SRC_MOD_DATE]
,[MKT_INFO_SRC_CLIENT_CODE] = stg_MKT_CUSTOM.[MKT_INFO_SRC_CLIENT_CODE]
,[MKT_INFO_SRC_CAT_CODE] = stg_MKT_CUSTOM.[MKT_INFO_SRC_CAT_CODE]
,[MKT_INFO_SRC_CAT_DESC_EN] = stg_MKT_CUSTOM.[MKT_INFO_SRC_CAT_DESC_EN]
,[MKT_INFO_SRC_CAT_DESC_FR] = stg_MKT_CUSTOM.[MKT_INFO_SRC_CAT_DESC_FR]
,[MKT_INFO_SRC_CAT_CREATE_DATE] = stg_MKT_CUSTOM.[MKT_INFO_SRC_CAT_CREATE_DATE]
,[MKT_INFO_SRC_CAT_MOD_DATE] = stg_MKT_CUSTOM.[MKT_INFO_SRC_CAT_MOD_DATE]
,[IMPORT_DATE] = GETDATE()
from
nss.stg_MKT_CUSTOM
inner join
MKT_CUSTOM on (stg_MKT_CUSTOM.INS_MKT_INFO_SRC_ID = MKT_CUSTOM.INS_MKT_INFO_SRC_ID)
where
(stg_MKT_CUSTOM.MKT_INFO_SRC_MOD_DATE <> MKT_CUSTOM.MKT_INFO_SRC_MOD_DATE
or stg_MKT_CUSTOM.MKT_INFO_SRC_CAT_MOD_DATE <> MKT_CUSTOM.MKT_INFO_SRC_CAT_MOD_DATE)
If you need to perform an update action within data flow task, you need to use OLE DB Command component.
However as I cannot see any parameters/variables within your statement, you can try to use Execute Sql Task in control flow panel.
i this case i try to put your update in a new sql procedure,
and in execute sql-task I try to execute it.

Syntax Error (missing operator) in Access Query

I have a table named Services and it has two columns ID and Price. here is my code (VB.NET):
com.CommandText = "UPDATE Services SET Price =
(CASE WHEN (ID = 'Bedsheet') THEN #Bedsheet WHEN (ID = 'Comforter')
THEN #Comforter WHEN (ID = 'PressOnly') THEN #PressOnly WHEN (ID = 'WDF')
THEN #WDF WHEN (ID = 'WDP') THEN #WDP END) WHERE ID IN
('Bedsheet','Comforter','PressOnly','WDF','WDP')"
It always says a Syntax error (missing operator) in query expression message. What do I have to correct in my code?
Quoting from a person who gave me help, "The CASE syntax works in SQL/Server but is not supported in ACE (the Access native SQL driver)." I used the Switch() function instead and got the job done. here is my new code:
UPDATE Services SET Price = SWITCH(ID = 'Bedsheet', #Bedsheet, ID = 'Comforter', #Comforter, ID = 'PressOnly', #PressOnly, ID = 'WDF', #WDF, ID = 'WDP', #WDP)
WHERE ID IN('Bedsheet','Comforter','PressOnly','WDF','WDP')

Convert SQL Server Query to MS Access to Update Table

Could anyone help with this. I don't use Access often, but this process I'm building needs to utilize Access for the business to use. I have the following code, which will not work in Access. I keep getting the error 'Syntax Error (missing operator) in query expression'. Would anyone be able to convert this query into something Access will accept.
UPDATE Auto_DailyDiary_PrimaryTbl a
SET a.TotalDiary = sub.TotalDiary
FROM
(
SELECT CaseEEID, Count(CaseID) as TotalDiary
FROM dbo_Case
WHERE CaseStatus <> 6
GROUP BY CaseEEID
) sub
WHERE sub.EEID = a.EEID AND a.DiaryDt = Date()
Pretty sure Access doesn't like having a joined group by subquery in an update query.
Maybe try something like this?
UPDATE Auto_DailyDiary_PrimaryTbl
SET TotalDiary =
DCOUNT('CaseID', 'dbo_Case',
"CaseStatus <> 6 AND " &
"CaseEEID = '" & Auto_DailyDiary_PrimaryTbl.EEID & "'")
WHERE DiaryDt = Date()

Old Access Update Statement

We recently switched from Oracle to SQL Server and we had this old update statement that used to work but is now giving the error 'operation must be an updateable query'. Well the query type is set to Update, I have tried running it as administrator with no success and we are able to run select statements with no problem, so the connection must be ok?
I'm not sure if I'm just missing something really simple as I'm used to working in SSMS and not Access. The code for the Update statement is below:
UPDATE dbo_LEARNER_AIMS
INNER JOIN dbo_REGISTRATION_UNITS ON dbo_LEARNER_AIMS.RUL_CODE = dbo_REGISTRATION_UNITS.RUL_CODE
SET dbo_LEARNER_AIMS.END_DATE = [EXP_END_DATE],
dbo_LEARNER_AIMS.COMPLETION = "10",
dbo_LEARNER_AIMS.OUTCOME = "40",
dbo_REGISTRATION_UNITS.FES_PROGRESS_CODE = "EXT",
dbo_REGISTRATION_UNITS.FES_PROGRESS_DATE = [EXP_END_DATE],
dbo_REGISTRATION_UNITS.PROGRESS_STATUS = "X"
WHERE (((dbo_LEARNER_AIMS.END_DATE) Is Null)
AND ((dbo_LEARNER_AIMS.FUNDING_YEAR)="17")
AND ((dbo_LEARNER_AIMS.LEARNING_AIM) = [Enter Aim])
AND ((dbo_LEARNER_AIMS.EXP_END_DATE) Between #8/1/2012#
AND [enter expected end date]));
Thanks in advance to any answers.
the error 'operation must be an updateable query'.
almost always means an Indexing problem, usually a missing primary key.
also
check the properties page of the Query, look for the Snapshot vs Dynaset setting.
Try this query :
UPDATE dbo_LEARNER_AIMS
SET END_DATE = [EXP_END_DATE],
COMPLETION = "10",
OUTCOME = "40",
/*
dbo_REGISTRATION_UNITS.FES_PROGRESS_CODE = "EXT",
dbo_REGISTRATION_UNITS.FES_PROGRESS_DATE = [EXP_END_DATE],
dbo_REGISTRATION_UNITS.PROGRESS_STATUS = "X"
You can't update multiple table in one update statement ! */
FROM dbo_LEARNER_AIMS /* add this line */
INNER JOIN dbo_REGISTRATION_UNITS ON dbo_LEARNER_AIMS.RUL_CODE = dbo_REGISTRATION_UNITS.RUL_CODE
WHERE (((dbo_LEARNER_AIMS.END_DATE) Is Null)
AND ((dbo_LEARNER_AIMS.FUNDING_YEAR)="17")
AND ((dbo_LEARNER_AIMS.LEARNING_AIM) = [Enter Aim])
AND ((dbo_LEARNER_AIMS.EXP_END_DATE) Between #8/1/2012#
AND [enter expected end date]));