teradata

Aggregate periods using recursive queries

社会主义新天地 提交于 2019-12-13 03:29:56
问题 I need to merge overlapping periods (defined by FROM and TO variables) of sequential events (with identifier NUM) for each group (ID) with a "lookahead buffer", meaning that if the next period starts within the buffer zone, they should be merged. For instance; in the following example the second event (NUM = 2) starts at time 13, which is within the buffer zone (10 + 5 = 15). The tricky part here compared to other similar problems I've found is that although the buffer period has a fixed

Calculate time difference in Teradata

烈酒焚心 提交于 2019-12-13 03:24:04
问题 I have a scenario to calculate difference of timestamp in minute. There is one common field in 2 tables i.e dw_job_id and want to join 2 tables and guessing, calculate (scratch.COGIPF_RUNREPORT_test2.end_ts - concat(proct_dt, scratch.dw_job_sla_dim_test.sla_time) Example, Subtraction in minute: (2018-03-05 01:53:14.201000 - 2018-03-05 08:00:00.000000)= -366 It would be quite clear using below records: 1st query has end_ts: sel * from scratch.COGIPF_RUNREPORT_test2 where dw_job_id=1226 Result:

how to add date in Teradata?

天大地大妈咪最大 提交于 2019-12-13 02:55:18
问题 Hi i want to add 01/01/1970 to a column ,datatype of last_hit_time_gmt is bigint ,when i run the below query i am getting data type last_hit_gmmt does not match a defined datatype name. select distinct STG.OMN_APND_KEY, STG.last_hit_time_gmt, IIF(STG.last_hit_time_gmt <>0,ADD_TO_DATE(TO_DATE('01/01/1970', 'DD/MM/YYYY'),'SS',cast(STG.last_hit_time_gmt as DATE ),NULL) from EDW_STAGE_CDM_SRC.STG_OMNITUREDATA STG WHERE UPPER(STG_OMNITUREDATA.EVAR41) IN ('CONS_SUPP: CONSUMER','STORE','PURCHASE')

Teradata: [Error 1154] [SQLState HY000] A failure occurred while inserting the batch of rows

不问归期 提交于 2019-12-13 02:35:38
问题 I have connected to my Teradata database via JDBC and am trying to use the FASTLOAD utility of Teradata to insert records into a table (with prepared statements and batch). Eg: connection = DriverManager.getConnection("jdbc:teradata://192.168.1.110/TYPE=FASTLOAD", "admin", "admin"); String sql = "INSERT INTO table (RANDOM_INTEGER) VALUES (?)"; PreparedStatement preparedStatement = connection.prepareStatement(sql); int numberOfRecordsToInsert = 100000; for (int i = 0; i <

Teradata SQL Optimization : NOT IN ( List ) , Col <> and IN LIST Optimization

戏子无情 提交于 2019-12-13 00:55:49
问题 I have queuries with a LOT of these situations Sel TB1.C1 TB2.C2, TB3.C4 Tb5.C5 where < Join conditions involving all tables TB1 through TB4 . Most are inner some are LOJ > where TB2.C2 NOT In ( List ) OR TB3.C5 <> 'string' OR Tb5.C8 NOT IN ( another long list ) Is there a better way to rewrite the filter conditions NOT IN ( List ) , Col <> and IN LIST Optimization some of the cols are selected some are not which are there in the sel Vs the filter condition. 来源: https://stackoverflow.com

How to identify all rights for a Teradata user?

我们两清 提交于 2019-12-12 21:44:42
问题 I'm looking for a way to identify the default permissions granted to a user in a particular database. I have tried this: select * from dbc.allrights where username='user-id' and databasename='database-name' There are two problems with the above; first, as written, the query returns one row for each permisison for each table owned by the user-id and it includes permissions that were specifically granted. Second, if the user-d has not created any tables at all, no rows are returned. I'm hoping

Load Historical data to teradata temporal table

会有一股神秘感。 提交于 2019-12-12 18:37:57
问题 I have a task to load existing SQL Server table to Teradata temporal table. Existing table is a type 2 table and has many versions of record. I need to load them into teradata temporal table. I am planning to load version 1 1st and then update all other versions one by one. Difficulties i am having is that in existing table every record has start time and end time. I need to update that time in teradata temporal table as validity. 1st I am trying to insert and while insert i am not able to

Teradata SQL Syntax - Common Table Expressions

被刻印的时光 ゝ 提交于 2019-12-12 09:50:05
问题 When using multiple CTE's in MSSQL 2008, I normally separate them with a comma. But when I try this in a Teradata environment, I get an error with the syntax. Works in MS SQL: WITH CTE1 AS (SELECT TOP 2 Name FROM Sales.Store) ,CTE2 AS (SELECT TOP 2 ProductNumber, Name FROM Production.Product) ,CTE3 AS (SELECT TOP 2 Name FROM Person.ContactType) SELECT * FROM CTE1,CTE2,CTE3 Now, attempting to put into Teradata syntax: WITH RECURSIVE CTE1 (Name) AS (SELECT TOP 2 Name FROM Sales.Store)

Split The Column which is delimited into separate Rows in Teradata 14

假装没事ソ 提交于 2019-12-12 04:54:07
问题 Can any one help me in solving this. In a table, I have the data like this right now. How do i split the column Nodes which has delimiter TTBFA-TTBFB-TTBFC-TTBFD into 4 rows with other columns being same. california region GAXAEB 102,520,000 18.71 4 8/30/2014 california region TTBFA 92,160,000 23.33 3 9/13/2014 california region TTBFB 92,160,000 23.33 3 9/13/2014 california region TTBFC 92,160,000 23.33 3 9/13/2014 california region TTBFD 92,160,000 23.33 3 9/13/2014 The value for column

How to write a dynamic SQL code in Teradata?

拜拜、爱过 提交于 2019-12-12 04:15:33
问题 I am trying to convert this code (which accepts a column name as input, does calculations on the input column and inserts data into a table). Now that I know that we can't pass table/column names through a stored proc or macro, I came to know that we can do it through a dynamic SQL. I am not sure how the syntax should be as I could not find a clear and easy example. Below is my code which needs to be converted: INSERT INTO PROD_CE_WORK_SPACE.NPVAZ_CVM_CHECK_TEST_CASE_5 SELECT 'DURATION_CELL