Quantcast
Channel: Teradata Forums - Database
Viewing all 14773 articles
Browse latest View live

Sum distinct records in a table with duplicates - forum topic by txwylde

$
0
0

I have a table that has some duplicates. I can count the distinct records to get the Total Volume. When I try to Sum when the CompTia Code is B92 and run distinct is still counts the dupes.
 
Here is the query:

select
a.repair_week_period,
count(distinct a.notif_id) as Total_Volume,
sum(distinct case when a.header_comptia_cd = 'B92' then 1 else 0 end) as B92_Sum
FROM artemis_biz_app.aca_service_event a
where a.Sales_Org_Cd = '8210'
and a.notif_creation_dt >= current_date - 180
group by 1
order by 1
;

Is There a way to only SUM the distinct records for B92?
I also tried inner joining the table on itself by selecting the distinct notification id and joining on that notification id, but still getting wrong sum counts.
 
Thanks!

Forums: 

Inserting into table using multiple common table expressions CTE - forum topic by bmsouthern

$
0
0

Hi,
I'm wondering if someone has a workaround for performing an insert from a select statement inside of a CTE.  My CTE has multiple 'with' statements and from what I've been seeing, Teradata only supports an insert/select in a CTE with one 'with' statement.
Thanks

Forums: 

Filtering results of concatenation - forum topic by SQLfan123

$
0
0

Hi Everyone!
I'm having trouble with filtering concatenation results in Teradata. I'm using the following syntax "EXTRACT(YEAR from saledate)||EXTRACT(MONTH from saledate) AS date_num" to combine the year number with the month number for a variety of dates. This works great and the results are like the following "2005 4", "2008 9" etc.
However, when I try to select only a certain date pairing in a WHERE clause (WHERE date_num = '2005 4') for example, Teradata tells me no data is available. Why is it not recognizing the '2005 4'? Am I doing something wrong, or is there a workaround?
Thanks for any help!

Forums: 

Merge different rows in one row - forum topic by rychitre

$
0
0

I have huge data as below. ‘Act_dt,cust_id and cust_line_id’ should be unique key.

act_dt cust_id cust_line_id flg1 flg2 flg3 metric1 metric2 metric3
1-Jul   1111    1                       D                20
1-Jul   1111    1                 N          M                 10 
1-Jul   1111    1                 N                                        5
       
I want to have only 1 record as below.

act_dt cust_id cust_line_id flg1 flg2 flg3 metric1 metric2 metric3
1-Jul   1111    1                N    D    M     10        20         5

How can I do this? Can someone help?
 

Forums: 

MAX SPOOL BY AMP - forum topic by Dinesh1975

$
0
0

I am receiving the alert from viewpoint " Max spool by AMP".  60.19%.  Can you please let me know how to resolve it.

Forums: 

Inserting into table using multiple common table expressions CTE - response (1) by ToddAWalter

$
0
0

Teradata only supports one WITH. But within the one WITH it is possible to specify as many CTEs as desired.

Sum distinct records in a table with duplicates - response (1) by Fred

$
0
0

How about
count(distinct case when a.header_comptia_cd = 'B92' then a.notif_id else NULL end) - 1 /* Don't include NULL in the count */ as B92_Sum
 

Filtering results of concatenation - response (1) by Fred

$
0
0

It's the extra spaces introduced by implicit typecast from INTEGER result of extract. The default is FORMAT -(10)9 so the year, for example is 2005 with 5 leading spaces.
Explicitly CAST(EXTRACT(YEAR from saledate) as VARCHAR(4)), which trims the spaces, or rely on implicit cast but explicitly TRIM the result. You may want to explicitly concatenate a single space between year and month.
Or use FORMAT with CAST to explicitly control the result, e.g. CAST(CAST(EXTRACT(YEAR from saledate) AS FORMAT '9999') as VARCHAR(4)). This method would also allow you to have months less than 10 appear as two digits with a leading zero.


PPI - response (36) by kamlesh114

$
0
0

Thank you very much Todd.
I got it what i needed.
 

Can we pass object as parameter in a macro ? - response (4) by Deepakji

$
0
0

thanks Todd .. after your suggestion i tried with stored procedure .. but still i m a bit confused how to implement it with stored procedure.. can u please guide me ?
I m trying it .. but i m getting errors .. 
 

REPLACE PROCEDURE sysdba.new_date2 (tablename1 varchar(200),databasename1 varchar(200))

 

DYNAMIC RESULT SETS 2

BEGIN

declare create_user_sql char(500);

DECLARE date1 CURSOR WITH RETURN ONLY FOR

sel  tablename from dbc.tables where tablename=tablename1 and databasename=databasename1;

open date1;

 

set create_user_sql='sel count(*) from '||databasename1||'.'||tablename1||';';

call dbc.sysexecsql(create_user_sql);

 

END;

 

Here i guess when i use sel statement in sysexecsql it is not accepting .. Could you please provide a solution for this ?

 

Merge different rows in one row - response (1) by sachin.sebastian

$
0
0

You could do this:
SEL Act_dt,cust_id and cust_line_id,MAX(flg1), MAX(flg2), MAX(flg3), MAX(metric1), MAX(metric2), MAX(metric3) 
FROM <TABLE>
GROUP BY 1,2,3

How to transpose row values - forum topic by sasnai

$
0
0

Hi, 
I have a data like
id    info
1     AB 1234 / CD 5678 / EF 9101.
I want output like this
id info
1 AB 1234
1 CD 5678
1 EF 9101
I tried using TD_UNPIVOT function but didnt get the required output.
Thanks in advance.

Forums: 

extract time from timestamp(6) - response (1) by sachin.sebastian

$
0
0

SELECT CAST(SUBSTR(CAST(<COL> AS VARCHAR(20)),12,19) AS TIME(0))

Output is different in DBC.diskspace and for Dbc.diskspacev - forum topic by vc

$
0
0

Hello,
When I am firing the below 2 query,I am getting the same output as  abc_stg,test_mdl,123_srci for databasename columns
But when I replace Dbc.diskspacev with dbc.diskspace the output is blank.
I am trying to fetch the same output using dbc.diskspace
 
Also can anyone pleqse explain why we have   three different type of view for most dbc objects like(dbc.diskspace,dbc.diskspacev,dbc.diskspacevx)is  there any difference ?which one should be considered?
 

SELECT 

DatabaseName (TITLE 'DatabaseName')

,SUM(MaxPerm)/(1024*1024*1024) (DECIMAL(15,6)) (TITLE 'Max Perm (GB)')

,SUM(CurrentPerm)/(1024*1024*1024) (DECIMAL(15,6)) (TITLE 'Current Perm (GB)')

,((SUM(CurrentPerm))/ NULLIFZERO (SUM(MaxPerm)) * 100) (DECIMAL(15,6)) (TITLE 'Percent Used')

FROM DBC.DiskSpacev

WHERE MAXPERM >0 and databasename like  any('%@_stg','%@_srci','%@_mdl','%@_prstn') ESCAPE '@'

GROUP BY 1

ORDER BY 1

 

SELECT

DatabaseName (TITLE 'DatabaseName')

,SUM(MaxPerm)/(1024*1024*1024) (DECIMAL(15,6)) (TITLE 'Max Perm (GB)')

,SUM(CurrentPerm)/(1024*1024*1024) (DECIMAL(15,6)) (TITLE 'Current Perm (GB)')

,((SUM(CurrentPerm))/ NULLIFZERO (SUM(MaxPerm)) * 100) (DECIMAL(15,6)) (TITLE 'Percent Used')

,cast (CURRENT_date as timestamp(0)) + ((current_time -time '00:00:00') hour to second(0)) As AS_ON

FROM DBC.DiskSpacev

WHERE MAXPERM >0 and DATABASEname  like any('%_stg','%_srci','%_mdl','%_prstn') 

GROUP BY 1

ORDER BY 1

 

Thank you in advance

 

Regards,

vc

 

 

 

 

 

 

 

 

 

 

Forums: 

Filtering results of concatenation - response (2) by SQLfan123

$
0
0

Thanks, Fred! I used this approach: "CAST(EXTRACT(YEAR from saledate) as VARCHAR(4))||''||CAST(EXTRACT(MONTH from saledate) as VARCHAR(4)) AS date_num" and it worked perfectly.


moving first 4 characters to last 4 characters - forum topic by efgeorge18

$
0
0

Hello,
I have a field time_key (bigint) that shows '20160817'
I want to format it so that it displays as '08172016' in the sql.
 
I've played around with trim,cast,substr, can't seem to get it to work.
Any help is much appreciated.
Eddie

Forums: 

Output is different in DBC.diskspace and for Dbc.diskspacev - response (1) by Fred

$
0
0

Where there are both, the views with "V" are the ones everyone should be using - since TD12. The ones without V are only for backward compatibility.
 
Currently, object names are Unicode VARCHAR. Previously they were Latin CHAR(30) so LIKE with the compatibility view requires trailing spaces or % to match.

Can we pass object as parameter in a macro ? - response (5) by Fred

$
0
0

You can't use SysExecSQL for a data-returning statement. You need to use a second (dynamic) cursor:
 
DECLARE sel_csr CURSOR FOR sel_stmt;
PREPARE sel_stmt FROM create_user_sql;
OPEN sel_csr;

ODBC TimeStamp - response (2) by wgfagundes

$
0
0

Hello Dieter,
Did not work.. any other ideia, for example, modify user to set a timezone or use a profile with a timezone to the user?
 

moving first 4 characters to last 4 characters - response (1) by efgeorge18

$
0
0

I resolved this one:
select
TO_CHAR(cast(cast(cast(table.column as CHAR(8) ) as DATE FORMAT 'YYYYMMDD')  as DATE FORMAT'MMDDYYYY'),'MMDDYYYY') AS converted

Viewing all 14773 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>