Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 DATEADD function using Field values

Author  Topic 

bendertez
Yak Posting Veteran

94 Posts

Posted - 2010-03-31 : 05:18:52
Hi

I'm trying to add a field in a select statement calculated a contract end that looks at a the date to customer field and their term field. Basically I want to work out a renewal date using the date to supplier and the term within the DATEADD function.

This is what i've tried but get the "Argument data type varchar is invalid for argument 2 of dateadd function.":

DATEADD(mm, +(M.TERM), M.DATETOCUSTOMER) as ContractEndDate

Can I use the the M.Term field within the DATEADD function in this way?

Thanks in advance.

Dave

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-03-31 : 05:21:18
What is the datatype of TERM?

Try this

DATEADD(mm, cast(M.TERM as int), M.DATETOCUSTOMER) as ContractEndDate

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

DBA in the making
Aged Yak Warrior

638 Posts

Posted - 2010-03-31 : 05:25:03
M.TERM is a varchar type. The second argument of the DATEADD function is an integer.

What does the term column represent? What sort of data does it contain?

There are 10 types of people in the world, those that understand binary, and those that don't.
Go to Top of Page

bendertez
Yak Posting Veteran

94 Posts

Posted - 2010-03-31 : 05:39:56
Hi

The data type was INT.

Thanks madhivanan your advice worked a treat.

Dave
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-03-31 : 05:42:14
quote:
Originally posted by bendertez

Hi

The data type was INT.

Thanks madhivanan your advice worked a treat.

Dave


If the datatype is INT, you can simply use

DATEADD(mm, M.TERM , M.DATETOCUSTOMER) as ContractEndDate

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -