join - TSQL - Joining two numeric fields but with different lengths -


sorry if basic question have been unable find answer on google etc.

i have 2 tables: table1, table2

table 1 has field 'accountno' 10 character numeric field (example: 1122334455)

table 2 has field 'subaccno' 12 character numeric field (example: 112233445501)

as can see subaccno same accountno additional 2 digits @ end ranging 01-99.

if want join 2 tables , have been trying this:

select * table1 join table2 on table1.accountno = table2.subaccno str(subaccno) '1122334455%%' 

as wildcard cannot performed on numeric data have attempted converting string wildcard last 2 characters. returns nothing.

is able offer advice? thanks!

how joining on subaccno column divided 100:

select * table1 join table2     on table1.accountno = table2.subaccno / 100 

actually, safe might want explicitly truncate quotient zeroth decimal place using round():

select * table1 join table2     on round(table1.accountno, 0, 1) = round(table2.subaccno / 100, 0, 1) 

Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -