SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Join two tables
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

jimdarter
Starting Member

13 Posts

Posted - 05/15/2012 :  11:48:18  Show Profile  Reply with Quote
Hi- I need to join two tables having the following common field. Is there a way to join them on this field 'ID' since in table 1 ID field has no zeros in front but in table 2 there are zeros infront until the number reaches 4 digits (zeros are only until 999).

Table-1
ID
3
6
7
9
10
12
98
111
232
777
999
1001
1112

Table-2
ID
0003
0006
0007
0009
0010
0012
0098
0111
0232
0777
0999

jimf
Flowing Fount of Yak Knowledge

USA
2868 Posts

Posted - 05/15/2012 :  11:54:21  Show Profile  Reply with Quote
SQL might do the conversion implicitly for you, but just to be sure
FROM table1
JOIN table2 ON table1.Id = convert(int,table2.ID)

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000