Solved

add 30 days before trigger date programatically?

Posted on 2007-04-11
4
234 Views
Last Modified: 2008-02-01
this is my query
SELECT ID, Contractname, triggerdate, Amount, ClientID FROM legalcontract
triggerdate is the date where we need to follow up to client for possible renewal.   i want to add to my query a field called 30days  which is 30 days before the triggerdate.  

how can u add that programmaticaly in tsql?
0
Comment
Question by:gianitoo
  • 2
4 Comments
 
LVL 5

Expert Comment

by:sphillips1971
ID: 18892790
You can pass a negative to the DATEADD function to perform a date subtraction:

SELECT DATEADD(day, -30, triggerdate) AS 30days
FROM legalcontract

Scott
0
 
LVL 1

Author Comment

by:gianitoo
ID: 18892851
can my query look like this  
SELECT ID, DATEADD(day, -30, triggerdate) AS 30days, triggerdate,Contractname, startdate, enddate, Amount, ClientID FROM legalcontract
0
 
LVL 5

Accepted Solution

by:
sphillips1971 earned 500 total points
ID: 18892869
Yes, you can add that as a column anywhere in your SQL

Scott
0
 
LVL 69

Expert Comment

by:Scott Pletcher
ID: 18893112
I know the answer has already been accepted but you want still want to consider this approach :-) ...

I suggest using a computed, or virtual, column.  This will keep the column definition in the table itself and not in any particular SELECT.  First, you add the column definition once to the table:

ALTER TABLE legalcontract
ADD notifydate AS DATEADD(DAY, -30, triggerdate)

Then you can SELECT it just like any other column.  For example:

SELECT ID, Contractname, notifydate, Amount, ...
FROM legalcontract
WHERE notifydate ...
ORDER BY notifydate
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question