MS SQL, Time difference

I am using MS-SQL 2005
Let say I have two table like below:

TableA                          TableB
----------                        -------------
ID_A                             ID_B
RegisterDate                ID_A
                                     AssignedDate

And I have use this query to select all the data from both tables:
Select registerdate,AssignedDate
From TableA a
Left Join Table B b ON b.ID_A = a.ID_A

So result came out well, but I wanted to include 'Duration Time' in the result. Example result will be something like this:

RegisterDate                   AssignedDate                  DurationTime
01/01/2008 01:00:00      01/01/2008 02:00:00         01:00:00

Can you experts help me!!!!
erin027Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

BinuthCommented:
try this
SELECT
	A.registerdate,
	B.AssignedDate,
	CASE WHEN b.AssignedDate IS NULL THEN '00:00:00' 
		ELSE
			CAST(((DATEDIFF(ss,A.registerdate,B.AssignedDate)/3600)) AS VARCHAR) + ':' + CAST(((DATEDIFF(ss,A.registerdate,B.AssignedDate)%3600)/60) AS VARCHAR) + ':' + CAST((((DATEDIFF(ss,A.registerdate,B.AssignedDate)%3600)%60)%60) AS VARCHAR)
		END AS DurationTime
FROM TableA A
LEFT JOIN TableB B ON B.ID_A = A.ID_A

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
erin027Author Commented:
Thank you so much!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2005

From novice to tech pro — start learning today.