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
 Join two tables

Author  Topic 

jimdarter
Starting Member

14 Posts

Posted - 2012-05-15 : 11:48:18
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
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2012-05-15 : 11:54:21
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
   

- Advertisement -