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,
tanj1035Asked:
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.

Vitor MontalvãoMSSQL Senior EngineerCommented:
But they are in the same format. Only the values are slightly different.
You can use CAST to compare them but you'll lose performance if they are indexed:
select * 
 from A a inner join B b on CAST(a. createdon AS SMALLDATETIME)= CAST(b. submittedtimestamp AS SMALLDATETIME)

Open in new window

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
Scott PletcherSenior DBACommented:
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)
tanj1035Author Commented:
Thanks for the hint, Scott.
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

From novice to tech pro — start learning today.