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 |
|
abcd
Yak Posting Veteran
92 Posts |
Posted - 2009-03-20 : 07:27:32
|
| hi all...i have four columns userid,intime,intime1,outtime,outtime2 ..all of varchar type.....i want to calculate sum((intime2-intime)+(outime2-outtime)) in simple language....main problem is coming in doing any mathematical operation on varchar value...i cant change my table specifications...please throw some light on above issue.... |
|
|
Nageswar9
Aged Yak Warrior
600 Posts |
Posted - 2009-03-20 : 07:32:50
|
| Try this once,select replace(CAST(REPLACE(SUBSTRING(CONVERT(VARCHAR(12), intime, 114),1,5),':','.') AS DECIMAL(18,2)) - CAST(REPLACE(SUBSTRING(CONVERT(VARCHAR(12), intime1, 114),1,5),':','.') AS DECIMAL(18,2)),'.',':') from table |
 |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2009-03-20 : 07:33:40
|
| you can convert them to dates convert(datetime,intime2) and do mathematical operations and that with DATEDIFF and DATEADDJim |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-03-20 : 09:52:44
|
| why are you using varchar for storing date values? will format be always consistent? |
 |
|
|
|
|
|
|
|