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.
| Author |
Topic |
|
bendertez
Yak Posting Veteran
94 Posts |
Posted - 2010-03-31 : 05:18:52
|
| HiI'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 ContractEndDateCan 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 thisDATEADD(mm, cast(M.TERM as int), M.DATETOCUSTOMER) as ContractEndDateMadhivananFailing to plan is Planning to fail |
 |
|
|
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. |
 |
|
|
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 |
 |
|
|
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 useDATEADD(mm, M.TERM , M.DATETOCUSTOMER) as ContractEndDateMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|