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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Convert to date

Author  Topic 

Stan1978
Starting Member

31 Posts

Posted - 2011-10-06 : 08:52:39
I want to compare two dates from separate tables. Currently I user the query below;


select dbo.Trans.AccountID,
(SELECT dbo.Property.[Value] FROM dbo.Property WHERE dbo.Property.AccountID = dbo.Trans.AccountID
and dbo.Property.Property = 'Creation') AS Registration,
max(CASE WHEN dbo.Trans.TransType = 'Deposit' AND DeltaCash < 0 THEN left(Transid,8) ELSE NULL END) AS LastDepDay

from dbo.Trans
group by dbo.Trans.AccountID


Which gives the following results;

AccountID-------Registration-------------------------LastDepDay
123-------------2011-07-16 01:00:00;10.159.11.2------20110801

How do I convert the dates into a format that I can compare? I hope this makes sense. Many thanks.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-06 : 09:00:09
what are datatypes of Transid and dbo.Property.[Value] ?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Stan1978
Starting Member

31 Posts

Posted - 2011-10-06 : 11:51:34
TransID is a bigint, property value is in this format 2011-07-16 01:00:00;10.159.11.2 - not sure what is is called.

How would I find that out?

Thank you.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-06 : 12:11:53
check the table definition

sp_help ' dbo.Property'

sp_help 'dbo.Trans'

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -