• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 267
  • Last Modified:

Adding days to a date then sorting by the new date

Hi All,

I'm having some trouble figuring out how to sort by a date which is not stored in the database but which is calculated on-the-fly on my webpage by adding a number of days to another date.

So we have the following fields in the table UserDetails:

Date (smalldatetime ('dd/mmyyyy')
Term (int)

I am trying to sort my results by DueDate (which is dynamically calculated and not stored as a field in the db) which is Date ('dd/mm/yyyy') + Term (number of days (int) ).

So I am wondering if there is anyway that inside my SELECT in my SQL statement I can actually create a new date AS DueDate which is the above sum?

Anyone have any ideas?

Cheers,
Brad
0
bradderick
Asked:
bradderick
  • 2
1 Solution
 
ColosseoCommented:
Hi there

Afraid I dont have SQL here at home so I cant test it first before suggesting it but I believe it should work

SELECT [Date] + Term AS DueDate
FROM UserDetails
ORDER BY  [Date] + Term

This should return the newly created DueDate field with the results sorted on DueDate

I cant remember if Date is a reserved word or not that is why it has square brackets around it.

HTH

Scott
0
 
bradderickAuthor Commented:
Thanks Scott! That worked really well and the ORDER BY worked using the alias DueDate as well.

It seems so simple :o) I really appreciate your help.

Cheers,
Brad
0
 
ColosseoCommented:
Your welcome, glad it worked for you and thanks for the grade

Cheers

Scott
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now