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 |
|
abhinav864
Starting Member
4 Posts |
Posted - 2010-09-15 : 17:31:22
|
| Hi I have two colums which are of varchar(25) and have values in them as 20081121 which mean 2008 is the year 11 is the month and 21 is date .I want to Subtract 2 similar column .Eg: STAT1DT STAT2DT 20081121 20081202The answer should be 9 days instead of something >9.I tried this code select DATEDIFF (dd ,convert(datetime,STAT1DT,101) ,convert(datetime,STAT2DT,101) )from NCT_Master .But I am getting the errorThe conversion of a varchar data type to a datetime data type resulted in an out-of-range value.If some one can help me in this i would really appreciate it Thank you. |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
abhinav864
Starting Member
4 Posts |
Posted - 2010-09-15 : 18:49:59
|
| The two dates i have shown is just an example.....the two columns STAT1DT and STAT2DT have 40000 rows in them .I need a code which subtracts the two colums STAT1DT and STAT2DT. |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
abhinav864
Starting Member
4 Posts |
Posted - 2010-09-15 : 19:09:54
|
| @ tkizerWhen i perform the above code it shows this errorMust declare the scalar variable "@STAT1DT" |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
abhinav864
Starting Member
4 Posts |
Posted - 2010-09-15 : 19:24:44
|
| Sry for the trouble but executed this select datediff(dd, cast(STAT1DT as datetime), cast(STAT2DT as datetime))from NCT_Master the error i get is The conversion of a varchar data type to a datetime data type resulted in an out-of-range value |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
|
|
|
|
|