teradata

Teradata SQL stack rows per user

十年热恋 提交于 2019-12-12 03:24:53
问题 Is there a way to stack/group string/text per user ? data I have USER STATES 1 CA 1 AR 1 IN 2 CA 3 CA 3 NY 4 CA 4 AL 4 SD 4 TX What I need is USER STATES 1 CA / AR / IN 2 CA 3 CA / NY 4 CA / AL / SD / TX I tried cross join and then another cross join however but the data spools out. Thanks! 回答1: I am not an expert but this should work. You may need to modify it a bit per your exact requirement. Hope this helps! CREATE VOLATILE TABLE temp AS ( SELECT USER ,STATES ,ROW_NUMBER() OVER (PARTITION

Insert Into table Teradata dynamic stored procedure SQL

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-12 02:53:54
问题 I am trying to create a Stored Procedure in Teradata that will accept various arguments. My query has 4 passes of SQL where it creates 3 lots of volatile tables. Within the Select statements is the SQL that I need to be dynamic and this is where I run into problems. Here is my SQL: CREATE PROCEDURE "mydb"."test_sp20" (DepID integer) --DepID is my parameter DYNAMIC RESULT SETS 1 SQL SECURITY OWNER BEGIN DECLARE q1 VARCHAR(10000); DECLARE cur1 CURSOR WITH RETURN ONLY TO client FOR s1; CREATE

Teradata Orderer Analytical Function not allowed in group by clause

橙三吉。 提交于 2019-12-12 02:43:25
问题 I am getting the error Teradata Orderer Analytical Function not allowed in group by clause when I run this query: SELECT CC.CASE_ID as CASE_ID, FIRST_VALUE(CC.CASE_OWN_NM) OVER(PARTITION BY CC.CASE_ID) as FST_AGNT_CASE_OWN_NM, FIRST_VALUE(CC.LSTMOD_BY_AGNT_PRFL_NM) OVER(PARTITION BY CC.CASE_ID) as FST_AGNT_PRFL_NM, LAST_VALUE(CC.CASE_OWN_NM) OVER(PARTITION BY CC.CASE_ID) as LST_AGNT_CASE_OWN_NM, LAST_VALUE(CC.LSTMOD_BY_AGNT_PRFL_NM) OVER(PARTITION BY CC.CASE_ID) as LST_AGNT_PRFL_NM, case when

Combining Rows in SQL Viia Recursive Query

泪湿孤枕 提交于 2019-12-12 02:36:53
问题 I have the following table. Animal Vaccine_Date Vaccine Cat 2/1/2016 y Cat 2/1/2016 z Dog 2/1/2016 z Dog 1/1/2016 x Dog 2/1/2016 y I would like to get the results to be as shown below. Animal Vaccine_Date Vaccine Dog 1/1/2016 x Dog 2/1/2016 y,z Cat 2/1/2016 y,z I have the following code which was supplied via my other post at "Combine(concatenate) rows based on dates via SQL" WITH RECURSIVE recCTE AS ( SELECT animal, vaccine_date, CAST(min(vaccine) as VARCHAR(50)) as vaccine, --big enough to

Teradata DATEDIFF Error

↘锁芯ラ 提交于 2019-12-12 02:29:05
问题 Hi i am getting an error as expected something like END keyword between DATEDIFF and ( for the below statement under select case when CC.CASE_STS_CD in ( 'Closed', 'Auto Closed') then DATEDIFF(second,CC.REC_DTTM_PST,CC.CRT_DTTM_PST) end as CASE_RES_DUR_IN_SECS, 回答1: Assuming that your fields are DATE datatype (otherwise you'll need to cast): SELECT CASE WHEN CC.CASE_STS_CD IN ('Closed','Auto Closed') THEN (CC.REC_DTTM_PST - CC.CRT_DTTM_PST) * 86400 END AS CASE_RES_DUR_IN_SECS 回答2: There's no

Teradata / Aster : Fast Export / ncluster_export using query

牧云@^-^@ 提交于 2019-12-11 23:55:13
问题 I am trying to export a query from Teradata Studio 14.10 / Aster using the ncluster_export command line function. I can't find a working example to go off of. Does anyone have one they could share? Also how would I actually run the script (ie ncluster_export myScript1.bat )? Assume the following : File location: 'myhomedir' Username: 'user1' Password: 'pass1' Outfile name: 'outFile1.csv' 回答1: If you want to export a result set from Teradata Studio then you can do that from the "Teradata

Teradata: use of aliases impacts EXPLAIN estimation of time

巧了我就是萌 提交于 2019-12-11 20:33:47
问题 I have a relative simple query SELECT , db1.something , COALESCE(db2.something_else, 'NA') AS something2 FROM dwh.db_1 AS db1 LEFT JOIN dwh.db_2 AS db2 ON db1.some_id = db2 = some_id EXPLAIN gives an estimated time of something more than 15 seconds. On the other hand, explain on the following, where we basically replaced the alias with the table name: SELECT , db1.something , COALESCE(db_2.something_else, 'NA') AS something2 FROM dwh.db_1 AS db1 LEFT JOIN dwh.db_2 AS db2 ON db1.some_id = db2

How to get the looop equivalent command in teradata

筅森魡賤 提交于 2019-12-11 20:00:34
问题 I am very new to Teradata. Here I dont see any looping command to execute the following-- Input Structure A B C -- -- -- 1 b c 1 d d 1 c d 1 fx b Output_Structure-- A B C -- -- -- 1 fx b 1 b c 1 c d 1 d d here if we implement with the CASE structure it will work, like CASE IF (B ='fx' THEN SELECT C AS A1) CASE IF(B!= 'fx' THEN SELECT C WHERE B=A1) but if the number of records are more then we need to implement through LOOP. So any suggestion on this. 回答1: This looks like a hierarchy, you need

Merge update Temporal

左心房为你撑大大i 提交于 2019-12-11 19:31:24
问题 Existing data in table test : (Temporal table) id name valid_dt 1 cat 2012-06-16 - 9999-12-31 Incoming Table : (Temporal) id name valid_dt 1 bat 2013-12-28 - 9999-12-31 After Merge update , test table should have id name valid_dt 1 cat 2012-06-16 - 2013-12-28 1 bat 2013-12-28 - 9999-12-31 Will It be possible in Teradata Temporal Merge update statement if i run it today? non working code i tried SEQUENCED VALIDTIME MERGE INTO test USING ( sel * from incoming ) H on id=H.id when matched then

Time interval overlaps - teradata

你离开我真会死。 提交于 2019-12-11 19:20:10
问题 I need help with interval overplaps. I have these records in one table (and much more): Example 1: Id---------StartDate------EndDate 794122 2011-05-10 2999-12-31 794122 2011-04-15 2999-12-31 794122 2008-04-03 2999-12-31 794122 2008-03-31 2999-12-31 794122 2008-02-29 2999-12-31 794122 2008-02-04 2999-12-31 794122 2007-10-10 2999-12-31 794122 2007-09-15 2999-12-31 Example 2: Id---------StartDate------EndDate 5448 2012-12-28 2999-12-31 5448 2011-06-30 2999-12-31 5448 2005-12-26 2011-06-30 5448