Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP SQL
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
Please Assist.
Posted 8-Jul-13 4:20am
Comments
gvprabu at 8-Jul-13 9:24am
   
Hi You need to show past 5 years in drop down right
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

select distinct year(column) from TableName order by ASC
  Permalink  
v2
Comments
Karwa_Vivek at 8-Jul-13 9:46am
   
select Distinct DATEPART (year, column) FY from TableName order by FY ASC
--thanks I used Like this
Rate this: bad
good
Please Sign up or sign in to vote.

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
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 505
1 Maciej Los 325
2 Richard MacCutchan 265
3 Mathew Soji 220
4 BillWoodruff 210
0 OriginalGriff 8,804
1 Sergey Alexandrovich Kryukov 7,457
2 DamithSL 5,689
3 Maciej Los 5,279
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web01 | 2.8.1411028.1 | Last Updated 8 Jul 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100