MAX SPOOL BY AMP - response (1) by Dinesh1975
Set multiple variable in one case statement - response (3) by nealvenna
Hi,
Code in SAS is a do loop. If you want to achive same thing then use 2 case statements, which is simple and easy solution.
case when RFRL_SRC_CD = '039' then 1
end var_first,
case when RFRL_SRC_CD = '039' then prcd_amt
end var_second
Thanks
Replacing table - response (2) by nealvenna
SAS work tables and Teradata Volatile tables are similar in a way that both exists only for Session. SAS allows to replace tables if they already exist, Teradata does not. You need to do what Rglass suggests that is to drop if table already exist.
Table A Left Outer JOIN Table B VS Table B Right Outer JOIN A - forum topic by Prashant_20986
Is Table A LEFT OUTER JOIN TABLE B same as TABLE B RIGHT OUTER JOIN TABLE A in in terms of output and performance?
(Regardless of data content and size of table A, and table B)
Single vs double quotes - forum topic by SGIT
Hello, in the following code , if i replace the single quotes arounf 'credit card' with double quotes, it looks for a column with name 'credit card' . can some one throw some light on how teradata interprets double and single quotes
case
when appl_for_prod_typ = '30' then 'CreditCard'
when appl_for_prod_typ in ('12','13') then 'Homeline Plan'
when appl_for_prod_typ = '41' then 'Overdraft'
when appl_for_prod_typ = '20' and APPL_FOR_SPCFC_SRVC_TYP = '06' then 'Royal Credit Line - Non Equity'
when APPL_FOR_SPCFC_SRVC_TYP in ('01','02') then 'Personal Loan'
when (appl_for_spcfc_srvc_typ = '09' and appl_for_purps_typ = 'DE') then 'Credit Card Limit Increase'
when (appl_for_prod_typ = '21' and APPL_FOR_SPCFC_SRVC_TYP = '06') then 'RCL Non Equity Limit Increase'
end as product,
Using WITH Statement Modifier instead of Temp Tables? - response (4) by teradatatester
Did DR160077 get resolved?
Table A Left Outer JOIN Table B VS Table B Right Outer JOIN A - response (1) by dnoeth
Yes, it's only a syntax variation.
Table A Left Outer JOIN Table B VS Table B Right Outer JOIN A - response (2) by Prashant_20986
Thanks
Single vs double quotes - response (1) by dnoeth
It's working as expected by Standard SQL (and similar in most DBMSes):
Single quotes oare string delimiters.
Double quotes are used for identifiers like column & table names. But in Teradata double quoted identifiers are not case sensitive (this is a deviation from Standard SQL)
SQL SECURITY OWNER - forum topic by mohtashim
We have implemented SQL Security OWNER in stored procedures. When we call a Stored procedure (SP1 in DB1), the SP1 inserts some rows in a table (TBL1 in DB2) in another database. When we create a trigger on TBL1 in DB2 database which inserts a row in log table TBL2 in DB2 then it give the following error:
SQLCODE= 5315, SQLSTATE=42J15, An owner referenced by user does not have INSERT WITH GRANT OPTION access to DB2.TBL2.Col1
- DB1 has INSERT WITH GRANT OPTION access to DB2
- USER executing SP1 has INSERT WITH GRANT OPTION access to DB2
- DB2 has INSERT WITH GRANT OPTION access to DB2
- Trigger and TBL2 are created by a stored procedure located in another database DB3
Can anyone tell me how to fix it?
Thanks and regards
Insert taking long - forum topic by krishna1985
Hi Gurus,
I have the below script everything works well but at the bottom of the script we have insert in to statement ie for UDRBSCMS.RCD_TPB_OVERALL_DECISION and its taking ages to load. I am not sure whats wrong here. We jsut have 60000 records.
DROPTABLE RCD_TPB_OVERALL_DECISION;
CREATETABLE .RCD_TPB_OVERALL_DECISION AS
(
SELECT *
FROM GLSEastHLOrigination_test
WHERE APPT_ORIG_C IN ('3PCL','3PDM','3POR')
AND METRIC1 = 'AppToRDFN'
AND UNTILDATE BETWEEN---'2016-08-20' and '2016-08-26'
DATE-60 AND DATE
)
WITHDATAPRIMARYINDEX (untildate)
;
--Alter theRCD_TPB_OVERALL_DECISION for additional fields to calculate the rolling 7 days median.
ALTERTABLE RCD_TPB_OVERALL_DECISION
ADD dt DATE,
ADD res INTEGER,
ADD from_dt DATE,
ADD to_dt DATE,
ADD DATA_FLAG_TYPE VARCHAR(255) CHARACTER SET LATIN NOT CASESPECIFIC
;
--Collect Statistics on the table to ensure columns are indexed appropriately which helps to optimise the query.
COLLECTSTATISTICS
COLUMN (APPT_ORIG_C)
,COLUMN(Homeseeker_F)
,COLUMN(NPW_F)
,COLUMN(Exception_Impact_CreditDecision)
,COLUMN(AMENDMENT_F)
,COLUMN(TTFD_Team)
ON RCD_TPB_OVERALL_DECISION
;
--Create volatile table which calculates the from and to date ranges to calculate the 7 days rolling median
---DROP TABLE RCD_DECISION_7_DAYS ;
CREATETABLE.RCD_DECISION_7_DAYS AS
(
SEL
A.APPT_ORIG_C
,A.Homeseeker_F
,A.NPW_F
,A.Exception_Impact_CreditDecision
,A.AMENDMENT_F
,A.TTFD_Team
,MAX( CAST( UNTILDATE AS DATE)) OVER (PARTITIONBY base_day. from_dt, base_day.to_dt ORDERBY base_day. from_dt) AS dt
,(a.CUST_DIFF) AS res
, base_day.FROM_dt
, base_day.to_dt
,'TIME TO DECISION'AS DATA_FLAG_TYPE
FROM RCD_TPB_OVERALL_DECISION A,
(
SEL
CAST(UNTILDATE AS DATE) AS DATE1
,B.DATE2-6 AS FROM_DT
,B.DATE2 AS TO_DT
FROM RCD_TPB_OVERALL_DECISION A
INNERJOIN
( SELECTDISTINCT
CAST(UNTILDATE AS DATE) AS DATE2
FROM UDRBSCMS.RCD_TPB_OVERALL_DECISION) B
ONCAST(A.UNTILDATE AS DATE)=B.DATE2
WHERE
DATE1
between date-60 and date --'2016-08-14'
AND
DATE1=DATE2 AND
DATE1 BETWEEN DATE2-6 AND DATE2
GROUPBY 1,2,3
) AS base_day
WHERE
--a.CHANNEL = 'BROKER'
--AND
CAST(a.UNTILDATE AS DATE) BETWEEN base_day.FROM_DT AND base_day.TO_DT
)
WITHDATA;
;
--Insert into RCD_TPB_OVERALL_DECISION table data for Time to Overall Decision rolling 7 days median.
INSERTINTO RCD_TPB_OVERALL_DECISION(
APPT_ORIG_C
,Homeseeker_F
,NPW_F
,Exception_Impact_CreditDecision
,AMENDMENT_F
,TTFD_Team,
dt,
res,
FROM_dt,
to_dt,
DATA_FLAG_TYPE
)
SELECT
APPT_ORIG_C
,Homeseeker_F
,NPW_F
,Exception_Impact_CreditDecision
,AMENDMENT_F
,TTFD_Team,
dt,
res,
FROM_dt,
to_dt,
DATA_FLAG_TYPE
FROM RCD_DECISION_7_DAYS
;
-------------------------DDL of RCD_TPB_OVERALL_DECISION--------
show table RCD_TPB_OVERALL_DECISION
CREATE SET TABLE RCD_TPB_OVERALL_DECISION ,NO FALLBACK ,
NO BEFORE JOURNAL,
NO AFTER JOURNAL,
CHECKSUM = DEFAULT,
DEFAULT MERGEBLOCKRATIO
(
APPT_I VARCHAR(255) CHARACTER SET LATIN NOT CASESPECIFIC,
APPT_N VARCHAR(20) CHARACTER SET LATIN NOT CASESPECIFIC,
STUS_C VARCHAR(6) CHARACTER SET LATIN NOT CASESPECIFIC,
STUS_M VARCHAR(40) CHARACTER SET LATIN NOT CASESPECIFIC,
start_appt TIMESTAMP(6),
end_appt DATE FORMAT 'yyyy-mm-dd',
metric1 VARCHAR(40) CHARACTER SET LATIN NOT CASESPECIFIC,
FromDate TIMESTAMP(6),
start_team TIMESTAMP(6),
end_team DATE FORMAT 'yyyy-mm-dd',
WIM_st_bd INTEGER,
WIM_st_cd INTEGER,
UntilDate DATE FORMAT 'yyyy-mm-dd',
tWIM_end_bd_C INTEGER,
tWIM_end_cd_C INTEGER,
tWIM_end_bd_T INTEGER,
tWIM_end_cd_T INTEGER,
APPT_ORIG_C CHAR(4) CHARACTER SET LATIN NOT CASESPECIFIC,
appt_crat_d DATE FORMAT 'yyyy-mm-dd',
WIM_diff_C INTEGER,
WIM_diff_T INTEGER,
WIM_diff_C_dt DECIMAL(38,2),
WIM_diff_C_dt_cal DECIMAL(38,2),
WIM_diff_T_dt DECIMAL(38,2),
WIM_diff_T_dt_cal DECIMAL(38,2),
PURP_TYPE_C CHAR(50) CHARACTER SET LATIN NOT CASESPECIFIC,
PURP_X VARCHAR(255) CHARACTER SET LATIN NOT CASESPECIFIC,
PurpGroup VARCHAR(12) CHARACTER SET UNICODE NOT CASESPECIFIC,
"Origination State" VARCHAR(255) CHARACTER SET LATIN NOT CASESPECIFIC,
AppRegion VARCHAR(255) CHARACTER SET LATIN NOT CASESPECIFIC,
CTU_F VARCHAR(100) CHARACTER SET UNICODE NOT CASESPECIFIC,
OffThePLan_F VARCHAR(100) CHARACTER SET UNICODE NOT CASESPECIFIC,
HomeSeeker_F VARCHAR(100) CHARACTER SET UNICODE NOT CASESPECIFIC,
Simple_F CHAR(1) CHARACTER SET LATIN NOT CASESPECIFIC,
ProgressPayment_F VARCHAR(100) CHARACTER SET UNICODE NOT CASESPECIFIC,
tWIM_Newappt_bd INTEGER,
tWIM_Newappt_cd INTEGER,
Newappt TIMESTAMP(6),
eff_flag BYTEINT,
Metric VARCHAR(25) CHARACTER SET UNICODE NOT CASESPECIFIC,
"Loan Amount" VARCHAR(400) CHARACTER SET UNICODE NOT CASESPECIFIC,
Target BYTEINT,
Exclusions VARCHAR(13) CHARACTER SET UNICODE NOT CASESPECIFIC,
start_dt TIMESTAMP(6),
end_bd INTEGER,
start_bd INTEGER,
Team_diff INTEGER,
Cust_diff INTEGER,
refresh_date DATE FORMAT 'yyyy-mm-dd',
Valuation_F CHAR(1) CHARACTER SET LATIN NOT CASESPECIFIC,
DocIss_POS_F CHAR(1) CHARACTER SET LATIN NOT CASESPECIFIC,
DocIss_GLS_F CHAR(1) CHARACTER SET LATIN NOT CASESPECIFIC,
AutoDecision_F CHAR(1) CHARACTER SET LATIN NOT CASESPECIFIC,
AutoClose_F CHAR(1) CHARACTER SET LATIN NOT CASESPECIFIC,
NPW_F VARCHAR(100) CHARACTER SET LATIN NOT CASESPECIFIC,
Exception_Impact_CreditDecision INTEGER,
Exception_Impact_CreditDecision_NumExceptions INTEGER,
AMENDMENT_F VARCHAR(5) CHARACTER SET LATIN NOT CASESPECIFIC,
TTFD_Team VARCHAR(50) CHARACTER SET LATIN NOT CASESPECIFIC,
dt DATE FORMAT 'yyyy-mm-dd',
res INTEGER,
from_dt DATE FORMAT 'yyyy-mm-dd',
to_dt DATE FORMAT 'yyyy-mm-dd',
DATA_FLAG_TYPE VARCHAR(255) CHARACTER SET LATIN NOT CASESPECIFIC)
PRIMARY INDEX ( APPT_I );
between condition make bad execution plan - forum topic by knowledge
Hi,
i have a query like this:
sel * from tbla a inner join tblb b on a.TheDay between b.SDay and b.EDay;
this is the execution plan:
2) Next, we do an all-AMPs RETRIEVE step from
tbla by way of an all-rows scan with no condition into
Spool 2 (all_amps), which is duplicated on all AMPs. The size of
Spool 2 is estimated with high confidence to be 2,051,400 rows (
34,873,800 bytes). The estimated time for this step is 0.08
seconds.
3) We do an all-AMPs JOIN step from Spool 2 (Last Use) by way of an
all-rows scan, which is joined to b by way of an
all-rows scan with no residual conditions. Spool 2 and
b are joined using a product join, with a join
condition of ("(a.TheDay >= b.SDay) AND
(a.TheDay <= b.EDay)"). The input table
b will not be cached in memory, but it is eligible for
synchronized scanning. The result goes into Spool 1 (group_amps),
which is built locally on the AMPs. The result spool file will
not be cached in memory. The size of Spool 1 is estimated with
low confidence to be 625,636,195,428 rows (51,302,168,025,096
bytes). The estimated time for this step is 13 hours and 24
minutes.
there are all needed stats on PI and on join colum, i use the correct alias and the format date is 'yyy-mm-dd' on between the tables.
How can i do?
How can i cheat the parser to generate a plan without product join? (with or without the stats the exec plan is the same)
Thanks
between condition make bad execution plan - response (1) by dnoeth
There's no way to avoid the product join because it's not an equi-join.
What are you trying to achieve?
Table A is probably a calendar and you'll get multiple rows for each row in Table B.
If you really need that you better use EXPAND ON.
Insert taking long - response (1) by dnoeth
SET Table plus bad Primary Index ('3PCL','3PDM','3POR')?
Using WITH Statement Modifier instead of Temp Tables? - response (5) by dnoeth
AFAIK it will be resolved in TD16.
MAX SPOOL BY AMP - response (2) by Dinesh1975
Thank you. Update space utility did the trick.
I can't execute an SP that calls another SP inside - forum topic by juanalfonso
Hello,
I'm trying to execute a procedure (F_SEPARA_LETRAS_Y_NUMEROS) with another procedure called inside (F_QUITA_REPES) but I get the following error:
- CALL Failed. [3523] F_NOTAS_AL_FINAL: An owner referenced by user does not have EXECUTE PROCEDURE access to novaquality.F_QUITA_REPES
Both procedures were created with "SQL SECURITY CREATOR" and by the same user, the same one I'm trying to execute it with.
Also, if I execute the procedure inside (F_QUITA_REPES) on its own, it works.
What I do I have to do to be able to execute the one with the SP called inside?
Thanks and regards
Creating a Dynamic YoY Date Range in Case Statement for Current Quarter QTD - forum topic by kthumm11
Let's say I want to find YoY QTD Q3 unique customers and today is 9/1/2016. How do I make it so I do not need to manually need to update the bolded date ranges in the case when statement.
If today were 10/5/2016 the date ranges would automatically change to '2016-10-01' and '2016-10-04' then 'Q4_2016' / '2015-10-01' and '2015-10-04' then 'Q4_2015'
Col 1: Date
Col 2: UserId
select
count(distinct(userid)),
case when date between'2016-07-01'and '2016-08-31'then 'Q3_2016'
when date between '2015-07-01' and '2015-08-31' then 'Q3_2015' else '' end as dte_range
from table 1
where dte_range <> ''
Thanks
K
between condition make bad execution plan - response (2) by knowledge
Hi Dieter,
for every row in table b i have to check if the values of the field TheDay, this field have the dates continuous, is content between the fields SDay (Start Day) and EDay (End Day) for every row in the table a.
For example the field TheDay have the min value '2005-01-01' and the max value '2020-12-31',
the field SDay have the min value '2014-08-01' and the max value '2016-09-01',
the field EDay have the min value '2014-09-01' and the max value '2999-12-31'.
I tried to substitute the two fields SDay and EDay into one, to use the PERIOD() type to EXTRACT ON () but if i use it i can't insert some dates because the fileds b.SDay and b.EDay can have the same value.
how can i do?
TNX
between condition make bad execution plan - response (3) by ToddAWalter
What described above requires the product join, every row of b compared to every row of a. This is going to be expensive for a medium table joined to a large table. Are you sure there is no other join condition available - account, customerid,...?
One way to improve it some is to do a separate qualification of a.TheDay against the MIN of b.SDay since it appears that there rows in a.TheDay that won't qualify based solely on that criteria. That requires two selects unioned together, one to get the rows that are less than the max and one to join the rows greater than or equal to the max to table b.
Any one please respond.