| Author |
Topic |
|
inbs
Aged Yak Warrior
860 Posts |
Posted - 2009-01-16 : 02:04:03
|
hi,1.i have 2 columns:a - decimalb- varchara b1034 22:56 how can i find the difference between them?(b-a-->22:56-10:34)2.if i want the difference in hours between two columns,what types need to be a/b?thanks |
|
|
thiyagu_rind
Starting Member
46 Posts |
Posted - 2009-01-16 : 02:07:17
|
| If am not wrong you want results as 12:22 Is that right?RegardsThiyagarajan |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-01-16 : 02:17:14
|
| select replace(b,':','.')-a from urtable2.select datediff(hh,cast(replace(cast(10.36 as varchar(32)),'.',':') as datetime),cast('22:56' as datetime) )select datediff(hh,cast(replace(cast(a as varchar(32)),'.',':') as datetime),cast(b as datetime) ) |
 |
|
|
Jai Krishna
Constraint Violating Yak Guru
333 Posts |
Posted - 2009-01-16 : 02:17:46
|
| Use DATETIME Datatype for ur columns Jai Krishna |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2009-01-16 : 02:35:54
|
[code]DECLARE @a DECIMAL(4, 0), @b VARCHAR(5)SELECT @a = 1034, @b = '22:56'SELECT CAST(@b AS DATETIME) - CAST(STUFF(REPLACE(STR(@a, 4), ' ', '0'), 3, 0, ':') AS DATETIME)[/code] E 12°55'05.63"N 56°04'39.26" |
 |
|
|
inbs
Aged Yak Warrior
860 Posts |
Posted - 2009-01-16 : 05:39:47
|
| is any type columns of TIME?i get column b as 22:56 (from source) ,what should be column type destination?is datetime get just field of time? |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-01-16 : 05:42:06
|
| r u using 2005 r 2008 |
 |
|
|
inbs
Aged Yak Warrior
860 Posts |
Posted - 2009-01-16 : 07:10:50
|
| in this model i use 2000 |
 |
|
|
inbs
Aged Yak Warrior
860 Posts |
Posted - 2009-01-16 : 07:46:35
|
if i get from source fields that means of them is hours.what should be the types of the fields in destination?as i say beforei get two fieldsa - decimalb- varchara b1034 22:56 thanks a lot who that help |
 |
|
|
|