SQL Server Join

Posted on 2008-01-30
Medium Priority
Last Modified: 2010-03-19
I have a table that I need to link to another table...
The problem is that on one table the field is a multi-use field and is in varchar(50) format and the field I want to join on is datatime

The varchar filed gets the date as  mm/dd/yyyy

How do I do a join from varchar(50)  (mm/dd/yyyy to datetime?
Question by:lrbrister
  • 2
LVL 23

Expert Comment

by:Ashish Patel
ID: 20776597
select * from table1 a
inner join table2 b on a.varcharfield = Cast( b.DateTimeField as varchar(50))
LVL 23

Accepted Solution

Ashish Patel earned 2000 total points
ID: 20776607
if your varchar field has values like mm/dd/yyyy then use this.

select * from table1 a
inner join table2 b on a.varcharfield = Convert( varchar(10), b.DateTimeField, 101)

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
SQL Database Recovery Software repairs the MDF & NDF Files, corrupted due to hardware related issues or software related errors. Provides preview of recovered database objects and allows saving in either MSSQL, CSV, HTML or XLS format. Ensures recov…
Stellar Phoenix SQL Database Repair software easily fixes the suspect mode issue of SQL Server database. It is a simple process to bring the database from suspect mode to normal mode. Check out the video and fix the SQL database suspect mode problem.

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question