Old Access Update Statement - sql

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]));

Related

Update using Sum -Error

Keep on getting error
you tried to execute a query that does not include the specified expression
My SQL looks as follows:
UPDATE TblField LEFT JOIN TblTempStats ON TblField.DomainCatID = TblTempStats.DomainCatID
SET TblTempStats.EmptyFields = Sum(IIf([fieldname] Is Null,1,0));
Any ideas as to why?
You should use a domain aggregate for this in my opinion, it avoids the error:
UPDATE TblTempStats
SET TblTempStats.EmptyFields =
DSum(
"IIf([fieldname] Is Null,1,0)",
"TblField",
IIf(
TblTempStats.DomainCatID Is Null,
"TblField.DomainCatID Is Null",
"TblField.DomainCatID = " & TblTempStats.DomainCatID
)
)

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

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);

UPDATE same column multiple times in query

Is there a specified behavior for updating the same column 2+ times in the same UPDATE query, as follows?
UPDATE tbl SET a = 5, b = 'something', a = 6 WHERE c = 'whatever';
Is there a standardized behavior for this, or might it vary between flavors of SQL (e.g. it is "undefined behavior")? A cursory test with sqlite seems to indicate they are executed left-to-right, so the last column value will be the resulting one, but that doesn't imply that will always be the case.
Edit: The reason I'm trying to do this is I'm testing some SQL injection for a class project. One of the fields in an UPDATE is unsafely injected, and I'm trying to use it to overwrite previously SET fields from the same query.
This isn't exactly the answer you're looking for but assuming that the text "something" is a field you are passing in and it isn't parameterized or escaped you may be able to do this. This all depends on how the query is being built and what database it is being run against.
UPDATE tbl SET a = 5, b = 'something'; UPDATE tbl set a = 6;--' WHERE c = 'whatever';
by entering the following in the user input
something'; UPDATE tbl set a = 6;--
This assumes that the query is built dynamically something like this
var query = "UPDATE tbl set a = 5, b = '" + userInput + "' WHERE c = 'whatever'";
Here is a relevant question: How does the SQL injection from the "Bobby Tables" XKCD comic work?

Can't get update statement in SQL Server to work

I'm attempting to execute this SQL Update statement and it's not working. Does anyone know why ?
update dbo.EBSTable
set CommandField = replace(CommandField, '%APPL.mbm_aging_file', '%APPL.mbm_aging_file)')
where Command like '[%]APPL.mbm_aging_file'
Basically, I'm just trying to add a ")" to the end of the data appearing in the CommandField field where the value is %APPL.mbm_aging_file (The "%" actually appears in the data).
I discovered my where clause was inadequate (like me with SQL). It should read
update dbo.EBSTable set CommandField = replace(CommandField, '%APPL.mbm_aging_file', '%APPL.mbm_aging_file)') where Command like '%[%]APPL.mbm_aging_file%'
That statement worked.
update dbo.EBSTable
set CommandField = '%APPL.mbm_aging_file' + ')' -- or set CommandField = '%APPL.mbm_aging_file)'
where Command = '%APPL.mbm_aging_file'
You can do this, as you only need to add ) at the end only for this specific case.

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.