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.
Author |
Topic |
eljapo4
Posting Yak Master
100 Posts |
Posted - 2012-08-09 : 04:45:26
|
Hi I'm trying to Join 2 tables. Table A has a COL called Customer_Code here's some sample data from this COL:1000510 101470 101470 10390 10400 10420 10430 Table B has a COL called Customer_No here's some sample data from this COL: 010005100010147000101470000103900001040000010420 using a LIKE also returns (54104200)00010430I was trying something like this:SELECT * FROM TABLE A AINNER JOIN TABLE B B ON A.Customer_Code = (SELECT * FROM TABLE B WHERE B.Customer_No LIKE '%A.Customer_Code%' but I'm getting a SQL error can anyone help me on fixing the Join between the 2 tables please? |
|
stepson
Aged Yak Warrior
545 Posts |
Posted - 2012-08-09 : 05:01:04
|
hiyour problem is this : from TABLE Aand join TABLE B try this scriptSELECT * FROM [TABLE A] AINNER JOIN [TABLE B] B ON A.Customer_Code = B.customer_noS |
 |
|
eljapo4
Posting Yak Master
100 Posts |
Posted - 2012-08-09 : 05:12:58
|
Should have been more specific but my problem was on joining the 2 Cols. this this seems to work:SELECT * FROM TABLE A AINNER JOIN TABLE B B ON A.Customer_Code = CAST(B.Customer_No AS INT) |
 |
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2012-08-09 : 06:30:25
|
That will do an intger join. They must both be character so it would be clearer to code it asSELECT * FROM TABLE A AINNER JOIN TABLE B B ON cast(A.Customer_Code as int) = CAST(B.Customer_No AS INT)Note - this cannot use an index and it usually causes issues because the constraint on the table will allow what is in effect duplicates - e.g. 00001004 and 0001004.You would be better off holding the values as integers and converting for the client.==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-08-09 : 10:15:10
|
unless you've non numeric data on your columns i would make them of integer datatype------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|