Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
abhaysingh
Specialist II
Specialist II

SQL query

Hi all,

I want to extract data from SQL with max (YEAR) and max(month) at raw level extraction..

what shud be qyery for that?

pls suggest

6 Replies
giakoum
Partner - Master II
Partner - Master II

select * from table

where year(date) = (select max(year) from table)

or something similar

we need more details to answer that

jonathandienst
Partner - Champion III
Partner - Champion III

A subquery like this is one way:

SELECT Year,

  Month,

  ...

FROM dbo.Table1

WHERE Year = Select(Max(Year) FRO dbo.Table1)

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
abhaysingh
Specialist II
Specialist II
Author

Hi ioannis,

below suggested working fine

select * from table

where year(date) = (select max(year) from table)

but below desired query does not giving any output

select * from table

where year(date) = (select max(year) from table) and month(date) = (select max(Period) from table);

pls suggest..

its_anandrjs

Why not you try for incremental load logic for this.

Regards,

Anand

Anil_Babu_Samineni

abhay singh wrote:

but below desired query does not giving any output

select * from table

where year(date) = (select max(year) from table) and month(date) = (select max(Period) from table);

pls suggest..

From This, Might you require this

Load * From Table

where Year = Max(Year) and Month = Max(Month);

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
giakoum
Partner - Master II
Partner - Master II

Hi.

Most likely the format is different. Try using the to_date function to make them match.