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 240
1 Kamal Rocks 184
2 PIEBALDconsult 150
3 BillWoodruff 148
4 Jochen Arndt 135
0 OriginalGriff 5,695
1 DamithSL 4,506
2 Maciej Los 4,007
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,190


Advertise | Privacy | Mobile
Web03 | 2.8.141216.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