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 |
|
nikoo56
Starting Member
26 Posts |
Posted - 2012-02-29 : 12:44:00
|
| I have 2 column in my query that return time format for example, The first column returns 3:20 and the next one return 2:40 , I like to have a new column that return the sum of these 2 column.Column 1:Select ltrim(xfer_1_elapsed/60) +':' + REPLACE(SPACE(CASE WHEN xfer_1_elapsed%60< 10 THEN 1 ELSE 0 END) + LTRIM(xfer_1_elapsed%60), ' ', '0') as xfer_1_elapsed, column 2:case when second_rep != orig_rep then ltrim((xfer_2_elapsed - xfer_1_elapsed)/60) +':' + REPLACE( SPACE(CASE WHEN (xfer_2_elapsed - xfer_1_elapsed)%60 < 10 THEN 1 ELSE 0 END), ' ', '0') + LTRIM((xfer_2_elapsed - xfer_1_elapsed)%60) else null end as xfer_2_elapsedwhat should I write for column 3 to do the sum? (please reply if you can write it) |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2012-02-29 : 22:55:49
|
| [code]select *, col3 = col1+col2from ( -- Test Data select col1 = convert(datetime,'3:20') ,col2 =convert(datetime,'2:40') ) a[/code] Results:[code]col1 col2 col3----------------------- ----------------------- -----------------------1900-01-01 03:20:00.000 1900-01-01 02:40:00.000 1900-01-01 06:00:00.000[/code]CODO ERGO SUM |
 |
|
|
|
|
|