13,000,017 members (46,256 online)
Rate this:
See more:
I have a Table Containing Dates .
From this Table of Dates which Contains
dates from previous 5 years till Now.
I have the Requirement to Load a DropDownBox in Classic Asp
with the Years Available in the Table
I want to load the DropDownBox with Distinct years from the
Table in ascending order.the problem is I dont have Years in the table
whereas have the Transaction Dates Till now.
How can I achieve this.
I want the Sql Query to get All the Distinct Years in the
table from the Dates in the Table
Posted 8-Jul-13 3:20am
gvprabu 8-Jul-13 9:24am

Hi You need to show past 5 years in drop down right

Rate this:

## Solution 1

`select distinct year(column) from TableName order by ASC`
v2
Karwa_Vivek 8-Jul-13 9:46am

select Distinct DATEPART (year, column) FY from TableName order by FY ASC
--thanks I used Like this
Rate this:

## Solution 2

Hi,

Try like below Query

```IF NOT EXISTS(SELECT * FROM table_name)
BEGIN
SELECT YEAR(GETDATE())-4 'YearList'
UNION ALL
SELECT YEAR(GETDATE())-3
UNION ALL
SELECT YEAR(GETDATE())-2
UNION ALL
SELECT YEAR(GETDATE())-1
UNION ALL
SELECT YEAR(GETDATE())
END
ELSE
BEGIN
SELECT TOP 5 T.YearList
FROM (SELECT DISTINCT YEAR(DateColumn) 'YearList' FROM table_name ) T
ORDER BY T.YearList ASC
END```

Regards,
GVPrabu
v2

Top Experts
Last 24hrsThis month
 RickZeeland 155 Jochen Arndt 60 Michael_Davies 40 ppolymorphe 40 Bharat Leel 35
 OriginalGriff 4,557 ppolymorphe 2,292 RickZeeland 2,162 Kornfeld Eliyahu Peter 1,973 Richard Deeming 1,593