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.
Related
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.
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);
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?
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]));
Configuration
SQL 2005 (Server A) replicates to SQL 2008(Server B) which replicates to SQL 2008(Server C).
I recently added a column (to Server A) to a replicated table via script & the DDL change replicated to Server B with out a problem. When the DDL change replicated to Server C, I received the error below.
'DDL replication failed to refresh custom procedures, please run "exec sp_register_custom_scripting 'CUSTOM_SCRIPT', your_script, 'EDI from xx', 'table_name_here' "and try again (Source: MSSQLServer, Error number: 21814)'
These subscriptions (on Server B to Server C) were created via a script below.
**exec sp_addsubscription #publication = N'EDI to XLOCX', #subscriber = N'RXLOCXS-SQLA', #destination_db = N'EDI', #subscription_type = N'Push', #sync_type = N'replication support only', #article = N'all', #update_mode = N'read only', #subscriber_type = 0
exec sp_addpushsubscription_agent #publication = N'EDI to XLOCX (Merge)', #subscriber = N'RXLOCXS-SQLA', #subscriber_db = N'EDI', #job_login = N'ROUSES.COM\RXLOCXSQLREPL', #job_password = N'XPASSWORDX', #subscriber_security_mode = 1, #frequency_type = 4, #frequency_interval = 1, #frequency_relative_interval = 1, #frequency_recurrence_factor = 1, #frequency_subday = 8, #frequency_subday_interval = 1, #active_start_time_of_day =3300, #active_end_time_of_day = 235959, #active_start_date = 20070923, #active_end_date = 99991231, #enabled_for_syncmgr = N'False', #dts_package_location = N'Distributor'**
GO
So the million dollar question is, why do I get the error 'exec sp_register_custom_scripting 'CUSTOM_SCRIPT', your_script' when I add a column to a table in the EDI to XLOCX publication???
AHIA,
LarryR...
Sounds like a custom stored procedure (SP) is used to replicate the data. The custom SP needs to be updated to reflect the column change. The SP needs to be updated on all servers. The information about custom procedures will be associated with the article and not the subscription.
If you're not using, the you'll need to determine why the article thinks it needs a custom procedure.