Solved

add 30 days before trigger date programatically?

Posted on 2007-04-11
4
235 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

730 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