Transpose of data - response (2) by TDThrottle
How to ensure atomic nature of multiple table actions? - response (7) by sdc
Dieter, I am using your suggested method with success. Thanks for your help!
FYI for anyone's future reference, I had to put a semicolon after "BEGIN TRANSACTION".
SELECT Failed 3707 Syntax error, expected something like an 'EXCEPT' keyword or an 'UNION' keyword or a 'MINUS' keyword between - forum topic by bthurman
Below if the SQL I am trying to get to run. I am receiving the following error message upon execution: SELECT Failed 3707 Syntax error, expected something like an 'EXCEPT' keyword or an 'UNION' keyword or
a 'MINUS' keyword between ')' and the word 'z'
Here is the code:
with dqry_cc ( mop_cd, mop_desc, group_branch_id, ecr_tmz_name ,
stn_stn_id , stn_id, grp_brn_id ) as
(
select
a.mop_cd ,
a.mop_desc,
so.group_branch_id ,
t.ecr_tmz_name,
so.stn_stn_id,
s.stn_id ,
s.grp_brn_id
from
rfs.stn_ops_hierarchies so,
rfs.mthd_of_pymts a,
rfs.stns s,
rfs.tmzs_map t
where
s.stn_id = so.stn_stn_id
and a.mpt_mop_type_code = 'CC'
and S.TMZ = T.TMZS_TMZ
and so.group_id ='01'
and so.region_cd = 'RGN_stl_99'
and so.group_branch_id ='0101'
)
select *
from
(
select
cc.group_branch_id as GpBr,
cc.mop_desc as Descr,
CAST(SYSLIB.ERAC_GMT_TO_LCL(p.pymt_dt, cc.ecr_tmz_name) AS timestamp(6)) as LocalPaydate,
cast(SYSLIB.ERAC_GMT_TO_LCL(p.pymt_dt, cc.ecr_tmz_name) as date) as ph_pymt_dt,
dr.dvr_srnm as DriverFName,
dr.dvr_frst_name as DriverLName,
b.cr_card_hld_name as HolderName,
cast(ra.ecr_ticket_no as varchar(30))as ECARS2,
p.doc_nbr as ECARS1,
b.rea_rnt_agr_nbr as RntAgrNo,
p.pymt_amt as AMOUNT,
p.cur_curr_cd as Curr,
cast('XXXXXXXXXXXX'||COALESCE(b.last_four_cc_nbr, b.CR_CARD_NBR ) as varchar(24)) as CardNo,
cast(b.cr_card_exp_dat as date format 'mm/yy')as ExpireDate,
cast(
case substr(p.pymt_typ,1,1)
when 'R' then
-p.auth_amt
else
case substr(p.pymt_typ,2,1)
when 'R' then
-p.auth_amt
else
p.auth_amt
end
end
as decimal (15,3)) as AUTH_AMT,
cast(p.auth_date as date format 'mm/dd/yyyy') as AuthDate,
p.auth_nbr as AuthNo,
b.card_auto_swiped as Swipe,
rc.rv_meaning as PType
from
dqry_cc cc,
rfs_rv.rnt_agr_mthd_pymts b,
rfs_rv.rnt_agrs ra,
rfs.cg_ref_codes rc,
rfs.PYMTS p
left outer join
(
select dvr.dvr_srnm,
dvr.dvr_frst_name,
dvr.rdy_rnt_agr_nbr,
dvr.main_dvr_flg
from rfs_rv.dvr_rras
dvr
where dvr.main_dvr_flg = 'MR'
) dr
on p.ram_rea_rnt_agr_nbr = dr.rdy_rnt_agr_nbr
where
cc.mop_cd = b.mop_mop_cd
and b.rea_rnt_agr_nbr = ra.rnt_agr_nbr
and p.sta_stn_Id = cc.stn_stn_id
and b.rea_rnt_agr_nbr = p.ram_rea_rnt_agr_nbr
and b.seq_nbr = p.ram_seq_nbr
and p.pymt_typ = rc.rv_low_value
and p.pymt_typ not in ('X','A','DS')
and rc.rv_domain = 'PYMTS.PYMT_TYP'
-- and ph_pymt_dt = ?
union
all
(select
cc.group_branch_id as GpBr,
cc.mop_desc as Descr,
cast(SYSLIB.ERAC_GMT_TO_LCL(ph.pymt_dt, cc.ecr_tmz_name) AS timestamp(6)) as LocalPaydate,
cast(SYSLIB.ERAC_GMT_TO_LCL(ph.pymt_dt, cc.ecr_tmz_name) as date) as ph_pymt_dt,
dr.dvr_srnm as DriverFName,
dr.dvr_frst_name as DriverLName,
ph.name as HolderName,
pd.ticket_no as ECARS2,
cast( case when rb.ecr_lgcy_resv_nbr is null then
case when substr(pd.ticket_no,1,1) = 'D' then
'D'||substr(pd.ticket_no, 2,6)
else
null
end
else 'D'||rb.ecr_lgcy_resv_nbr
end as CHAR(7)) as ECARS1,
rb.rnt_agr_nbr as RntAgrNo,
case when ph.cr_card_trans_typ_cde='R' then
-1*pd.pymt_amt
else
pd.pymt_amt
end as AMOUNT,
pd.cur_curr_cd as Curr,
ph.CR_CARD_NBR as CardNo,
cast(ph.exp_dt as date format 'mm/yy') as ExpireDate,
cast(0 as decimal(15,3)) as AUTH_AMT,
cast(null as date format 'mm/dd/yyyy') as AuthDate,
ph.auth_nbr as AuthNo,
cast(null as char(2)) as Swipe,
cast(null as varchar(60)) as PType,
cast(ph.paph_fin_trans_ref_id as decimal(19,0)) as REFID
from
dqry_cc cc,
rfs_rv.pre_applied_pymts_hdr ph,
rfs_rv.pre_applied_pymts_det pd
left outer join
(select
ra.rnt_agr_nbr,
ra.ecr_ticket_no,
ra.ecre_rent_cntrct_nbr,
ra.ecr_lgcy_resv_nbr,
cc.grp_brn_id --
from
rfs_rv.rnt_agrs ra,
dqry_cc cc
where ra.sta_stn_id_orig_co = cc.stn_id QUALIFY ROW_NUMBER() OVER(PARTITION BY ra.rnt_agr_nbr ORDER BY ra.rnt_agr_nbr) = 1
) rb
on pd.ticket_no = rb.ecr_ticket_no
left outer join
(select
dvr.dvr_srnm,
dvr.dvr_frst_name,
dvr.rdy_rnt_agr_nbr
from rfs_rv.dvr_rras dvr
where dvr.main_dvr_flg = 'MR'
) dr
on rb.rnt_agr_nbr = dr.rdy_rnt_agr_nbr
where ph.pymt_stn_id = cc.stn_stn_id
and ph.mop_mop_cd = cc.mop_cd
and ph.pymt_id = pd.pap_pymt_id
-- and ph_pymt_dt = ?
) z
left outer join
(select
ft.paymt_mdia_proc_sys_cde as Settlement,
ft.prim_acct_frst_six_dgt_nbr as First_Six,
ft.fin_tran_ref_id
from paymt.fin_tran ft) pft
on pft.fin_tran_ref_id = z.refid
Any and all help will be greatly appreciated
session with wrong DML - forum topic by dba_1234
Hi,
Has any one cam accross this issue ?
we have informatica job which runs every day trying to update a feild in the view.
but once in a while the session fails with error with "tablename" is not a table and from the query text i see it trying to alter a table.
And from the informatica log at the same timestamp error shows as table doesnt exist.
Databse version :14.0
client :14.10
Is it possible to convert query written for SQL server to be run on Teradata? - forum topic by teradata300
Hi all,
I had written a DB query to be run on SQL Server and the table structure was like:
pkey Home_Telephone ID EDU_ID City State Zip Menu_Selection Account_Number Billing_System Prin FTA Node Company Division Email_Addr Create_time system MAC_ID Service_Address 123456789 7778889999 00250087661438113227 5mm7mmm000000000mm10emm623300002 AAAAAAAA MS 31234 Tier1 1234567891234567 C 5500 0050 EC6664 0 0 abc@xyz.com 2015-07-28 14:53:52.000 8381 NULL 123 MAIN DR 123455789 2225558888 00250068021438191419 55n90nn000000000nn10ennn23300002 BBBBBBBB MS 35678 NULL 8542687456248952 C 6600 0040 MA6610 0 0 hgf@itf.com 2015-07-29 12:37:04.000 8381 NULL 456 CENTER RD
This type of data is available for past few months and Create_time column can be used as reference for timestamp. (Sorry, couldn't put the table in proper format)
step 1) What I am trying to do is if CURRENT_TIMESTAMP is say 2015-08-17 16:27:42.987
Then fetch count(ID) grouped by each state where Create_time is between 2015-08-17 16:00:00.000 to 2015-08-17 16:27:42.987.
step 2) Second step is to find count(ID) grouped by each state for past 7 days (Aug/10 to Aug/16) during the same 1 hour window 16:00:00.000 to 17:00:00.000 and take sum of count(ID) for past 7 days, and avegare count(ID) (divide sum by 7).
step 3) Third step is if the count(ID) for today (calculated in step1) is greater than average count(ID) then find the difference and display in a column (say Variance) and also calulate percentage deviation by using (Variance/average count(ID)) * 100 and display in a column say percentage.
I had formulated following query for doing this but it is for SQL server and now I have to modify it for Teradata as on long term, we'll be using Teradata.
Can someone suggest me if same query can be reused with minor modifications for Teradata as well and point those changes please?
--One week average call volume and %variance declare @w0s datetime declare @w0e datetime declare @w1s datetime declare @w1e datetime set @w0s=dateadd(hh,datediff(hh,0,getdate()),0) set @w0e=getdate() set @w1s=dateadd(dd,datediff(dd,0,getdate())/7*7-7,0) set @w1e=dateadd(dd,datediff(dd,0,getdate())/7*7,0) ;with PreAggregate as ( select state ,sum(case when create_time>=@w0s and create_time<@w0e then 1 else 0 end) as Call_Volume_This_hr ,sum(case when create_time>=@w1s and create_time<@w1e then 1 else 0 end)/7.0 as Avg_Call_Volume_Past_Week1 from ctirpts.dbo.cti_reporting where create_time>=@w1s and datepart(hh,create_time)=datepart(hour, getdate()) and state is not null group by state ) select PreAggregate.state , PreAggregate.Call_Volume_This_hr , PreAggregate.Avg_Call_Volume_Past_Week1 , InlineFunction.Variance , (InlineFunction.Variance/PreAggregate.Avg_Call_Volume_Past_Week1)*100 as 'Percentage_Variance' from PreAggregate cross apply ( select case when Call_Volume_This_hr < Avg_Call_Volume_Past_Week1 then 0 else Call_Volume_This_hr -Avg_Call_Volume_Past_Week1 end 'Variance' ) InlineFunction;
Decode non-displayed char non-spaces - response (4) by Shyamala6691
I need to mask the data as it has sensitive information. I tried using MD5 c-function. I am not sure how it works and when I ran the bteq script in MD5 function, it is giving me some error. Could any one please help me to understand the MD5 function or possibly any other solution to mask the data would also serve. Thanks in advance
Table Lock Issue.. - forum topic by aneelkumar04
Hi All,
I am loading the data from file to temptable using fastload after loading into main table using insert select. After temp table load complete Data got loaded into Main table using Insert select .This is automated process in our application.
one of my Script that running from Temp table to main table, I got below error.
Failure 2652 Operation not allowed: dbname.tablename is being Loaded.
Statement# 1, Info =0
I am unable to Unlock the above using release lock script (empty script)
For this I have run the below script..
#!/bin/ksh -x
fastload << EOD
errlimit 2;
sessions 8;
tenacity 1;
.logon server/userid,paswd;
BEGIN LOADING dbname.tablename;
END LOADING;
LOGOFF;
While running the above script i got below error..
RDBMS error 3706: Syntax error: expected something
between the word 'tablename' and the 'WITH' keyword.
Please suggest me how to unlock my table..
Thanks in advance...
Table Lock Issue.. - response (1) by aarsh.dave
Try removing dbname.tablename.
Just BEGIN LOADING and END LOADING.
--Aarsh Dave
TDWM Filter violation for Query Request; For Rule Name'Maximum Final Row Count' - forum topic by esharma
Hi Everyone,
I am getting error while creating volatile table. Can someone help me to understand this error. I normally run the same query everyday and it works fine .
TDWM Filter violation for Query Request; For Rule Name'Maximum Final Row Count'
Thanks
Ena
Table Lock Issue.. - response (2) by aneelkumar04
Suppose if i remove dbname and tablename how it will excute. how it will consider particular table got locked ?
Teradata Non-commercial Database - forum topic by moetimollo
Hi,
Is there a version of Teradata I can use on my laptop to play around?
Table Lock Issue.. - response (3) by nagendratrpth
.logon server/usrid,password;
begin loading fastload_table_name
errofiles error_table1,error_table2;
end_loading;
Table Lock Issue.. - response (4) by aneelkumar04
Hi Nagendra,
Thanks for you response.. The thing is , i got the error when i load the data from temp table to target using Insert select format.
Thanks
Anilkumar
Teradata Non-commercial Database - response (1) by dnoeth
There's a virtual machine: VMware
Within the VM there's the Teradata Linux client installed.
If you got a Windows laptop you might want to run queries from it, either using Teradata Studio or the full TTU - Windows Install client.
Is it possible to convert query written for SQL server to be run on Teradata? - response (1) by dnoeth
You will need more than minor modifications...
Datetime calculations usually differ a lot across DBMSes.
CROSS APPLY is MS proprietary syntax which doesn't exist in Teradata. But in your case it's easy to replace because you can simply re-use an alias.
In Teradata defining variables is only possible within Stored Procedures (and you might not have the right to create them).
This should return the same result in Teradata:
WITH params AS ( SELECT TO_TIMESTAMP(TO_CHAR(CURRENT_TIMESTAMP, 'yyyy-mm-dd hh24'),'yyyy-mm-dd hh24') AS w0s -- truncate to the current hour ,CURRENT_TIMESTAMP AS w0e ,CURRENT_DATE -8 AS w1s ,CURRENT_DATE -1 AS w1e ) SELECT state ,SUM(CASE WHEN create_time>=w0s AND create_time<w0e THEN 1 ELSE 0 END) AS Call_Volume_This_hr ,SUM(CASE WHEN create_time>=w1s AND create_time<w1e THEN 1 ELSE 0 END)/7.0 AS Avg_Call_Volume_Past_Week1 ,CASE WHEN Call_Volume_This_hr < Avg_Call_Volume_Past_Week1 THEN 0 ELSE Call_Volume_This_hr -Avg_Call_Volume_Past_Week1 END AS VARIANCE ,100 * VARIANCE / PreAggregate.Avg_Call_Volume_Past_Week1 AS Percentage_Variance FROM ctirpts.dbo.cti_reporting WHERE create_time>=w1s -- AND datepart(hh,create_time)=datepart(HOUR, getdate()) AND EXTRACT(HOUR FROM create_time)=EXTRACT( HOUR FROM CURRENT_TIMESTAMP) AND state IS NOT NULL GROUP BY state
CPU Secs for a stored Procedure - response (1) by kirthi
Did you try query band for the transcation inside your Stored Proc ?
SELECT Failed 3707 Syntax error, expected something like an 'EXCEPT' keyword or an 'UNION' keyword or a 'MINUS' keyword between - response (1) by nagendratrpth
-- and ph_pymt_dt = ?
) <sub_query_name>
union
all
SELECT * FROM
(select
How to move spaces when date is null in table while Fast export - response (6) by ananthpillai
case when(cast((X1_PRODUCT_EFF_DT(format 'YYYY-MM-DD')) as char(10)) is null) then '' else cast((X1_PRODUCT_EFF_DT(format 'YYYY-MM-DD')) as char(10)) end
That worked for me.
Varchar to date conversion - interesting observation - response (8) by FernandoRios
Hola muchas gracias dnoeth, Saludos.
SQL to get first day of month and last day of month but for 2 months ago - response (7) by dnoeth
TRUNC is an Oracle-function which strips of the time part of a Timestamp, the same as CAST(col AS DATE) in Teradata.
The optional parameter 'MON' truncates to the first of month, there's also 'Q' = quarter, 'Y' = year, 'W' = week starting on sunday, 'IW' = week starting on monday.
There's no option for LAST_DAY.
Of course you could simply look up those functions in the SQL Functions manual, although it's not really correct fro TRUNC :-)
If your using TD 14 and above, use TDSTATS.UDFCONCAT for transpose column to row
Thanks!!