ali raza

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

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');

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: