July 9, 2009 at 7:50 am
I am supposed to create a join condition between two tables.
1) This one with nvarchar data type and has real number like ...9944156
2) This one is varchar and has the same field with zeros added up in from so it becomes 10 char..
for instance the same field shown in (1) becomes 0009944156.
How can I compare these two to make it a.order_no=b.order_no
There is no other field to really use in the join condition. Please help
thanks
Su
July 9, 2009 at 9:58 am
You could cast the fields to int (not sure if there is a more efficient way):
from table1 a inner join table2 b on
cast(a.order_no as int) = cast(b.order_no as int)
July 9, 2009 at 11:07 am
Casting to an INT should work just fine. However, you *might* be able to get a slight performance increase by eliminating a function on one the join values and just pad the one value with zeros:from table1 a inner join table2 b on
RIGHT('0000000000' + a.order_no, 10) = b.order_no
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply