Link to home
Start Free TrialLog in
Avatar of tanj1035
tanj1035

asked on

SQL, how to cast the timestamp to the same format

Hi Experts,

In table A, the column " created on" has value "2015-06-02 10:27:11.787"
In table B, the column " submittedtimestamp" has value "2015-06-02 10:27:11.780"

I want to make those 2 columns to the same format, which means 2015-06-02 10:27=2015-06-02 10:27

select *
from A a inner join B b on a. createdon = b. submittedtimestamp

Can you help me on the query.

Thanks,
ASKER CERTIFIED SOLUTION
Avatar of Vitor Montalvão
Vitor Montalvão
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You can't avoid some amount of conversion.  But, for best performance, convert only one column, usually the one from the smaller table.  For example, say table A is very small compared to table B:

select *
from A a
inner join B b on b. submittedtimestamp >= dateadd(minute, datediff(minute, 0, a.createdon), 0) and b. submittedtimestamp < dateadd(minute, datediff(minute, 0, a.createdon) + 1, 0)
Avatar of tanj1035
tanj1035

ASKER

Thanks for the hint, Scott.