ali raza

C#, .Net ,Asp.net and my thoughts

Category Archives: teradata

update statement with select in teradata

hi all, i use following syntex for this


UPDATE T1 FROM (SELECT t2_1, MIN(t2_2) from T2 group by 1) as D (D1, D2)
SET Field2 = D2
WHERE Field1 = D1

 

So i solve my problem as

UPDATE XTZ.KPI FROM (SELECT CONVERTED_TARGET_QTY,NORMAL_VALUE,CRITICAL_VALUE FROM DP_UTL.PRODUCTION_KPI WHERE PACKAGE='SSPET-500') AS D(D1,D2,D3) SET
MaximumValue = D1
, NormalValue = D2
, CriticalValue = D3
WHERE KPIId=125;

 

Chears

How to get first date of last year in teradata Sql

While working on teradata we have to show some reports on database, for example MTD month to date, YTD year to date, While searching Records on The bases of YTD , I have to  Find records till start of last month and till today. The I have to create first date of  last years as follow

select cast(cast( CAST( EXTRACT(YEAR FROM CURRENT_DATE)-1 AS CHAR(4))||'0101' as date format 'yyyymmdd') as date format 'yyyy-mm-dd');