Teradata stored procedure - teradata

i am planning to write stored procedure (teradata) with bunch of update statements in it .i want to capture number of rows updated for each update statement into an audit table .so can some one help me with SQL?

You can use the ACTIVITY_COUNT variable within your stored procedure. For example:
UPDATE MyTable
SET col1 = 'val';
INSERT INTO MyAuditTable (ActivityCount)
VALUES (:ACTIVITY_COUNT);
Keep in mind this variable is only accessible within your SP.
TD Manual

Related

REPLACE is not working inside plsql procedure

I am writing a procedure with a cursor that take table name and column name from a lookup table we have in DB. This table has a mapping of table name and columns.
These two info I am collecting in a variable and running a select query to see if the data in that column is number or not. for example:-
select TO_NUMBER(REGEXP_REPLACE(v_landing_column,'',''))
from v_landing_table
Here v_landing_column is a column name and v_landing_table is a table name. One of the values in v_landing_column is 12,300 which is a number but because of , the loop flow is going into exception where I am dumping error record in a seperate table.
I tried using REPLACE also with above syntax but still flow is dumping this record with value 12,300 into error table. How to remove , from 12,300 inside plsql procedure using execute immediate?

Multi row and column update using R in postgres database

Problem: I want to update values (in multiple rows and columns) of a table in a postgres database using R.
I know that the sql update statement can be something like this but I assume looping over a set of such queries is inefficient:
UPDATE table
SET col1 = value1, col2 = value2, ...
WHERE col1 = "some-value"
Question: Is there a function available to only update particular rows (and potentially only a subset of the columns) of the table (similar to dbWriteTable)? If not, can you think of an efficient way/sql query of updating multiple rows in postgres and how to hand over the R object to the sql query?
EDIT: Assuming I have a foreign key and I don't want to turn on the ON DELETE CASCADE option, how could I efficiently update values in multi rows and columns for the parent table (I only want to update parent table, not child table)?
First, I would read in the data that needs to be updated from SQL to R. Second, I would delete the data to be updated in SQL. Third, I would append the updated data from R to SQL.

SQLite batch update of a column in a table

I am using SQLite and have the following SQL Statement which updates column active with true for just row 28.
update "customer" set "active"='true' where rowid=28
What I would like to do is batch update the entire customer table, active column to true. I would have thought a loop was the best method, but I don't think sqlite supports loops. Anyone advise me how I can update a column in a table so all the records contain the value the in them?
Thanks
update "customer" set "active"='true'
will do the job (just don't specify a where)

SQLite Trigger for Inserting values from different tables

I would like to create a trigger on SQLite to update one table with values from more than one table. I have tried the code below but navicat for Sqlite wont save my trigger. Could someone help?
BEGIN
INSERT INTO hdClassSet (setNo, class, type, regdate, acYear)
VALUES (((SELECT max(setNo) FROM hdClassSet)+1),
old.clID,
0,
(date('now','localtime')),
(SELECT acID FROM tblAcad WHERE actv1=1));
END
I managed to save and test the trigger without the last value and it works. How can I reference another table that does not start or affected by the trigger? I will be grateful!

Biztalk Insert or Update in to database using the SQL bindings

I have a requirement where the data from one database has to be selected and inserted or updated in to the other database depending on the destination. I have used the DBBinding to select from the source.In the destination do I have to use stored procedure to do this or selecting Insert and Update in the DBBinding will work for this.
You can use Insert or Update unless you have some complex requirement to do in stored procedure.
You should probably use a stored procedure for this and perform an upsert within it. You could use a Composite Operation to send all the data across to SQL in one transaction or investigate using a Table Value Parameter so you can send multiple rows to the stored proc (depending on the number of rows!).
To do this you would need to create a MAP between your source data and the Composite Schema.
This way you are only concerened with the schema of the stored procedure and the Composite Schema.
See:
https://msdn.microsoft.com/en-us/library/dd788136.aspx
HTH

Resources