| Author |
Topic |
|
rookie_sql
Constraint Violating Yak Guru
443 Posts |
Posted - 2009-11-17 : 10:51:58
|
| Hi am having a problem with joining product codes where the data i received in an extract has 000237 while in my product table the prod_code is 237.so when i try to join the ext_tbl to the prd_tbl via the prod_code i get an error. because they don't match. any ideas no how to table this ?ext_tbl prd_tbl 000237 237 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-11-17 : 10:56:28
|
If values for prod_code in both tables are always numeric then you can convert them:...join ext_tbl on convert(int,ext_tbl.prod_code) = convert(int,prd_tbl.prod_code)... No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
kbhere
Yak Posting Veteran
58 Posts |
Posted - 2009-11-19 : 06:25:24
|
| IF the values in both the tables are numeric, you can try the following..SELECT * FROM prd_tblJOIN ext_tbl ON ROUND(ext_tbl.prod_code) = ROUND(prd_tbl.prod_code)Balaji.K |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-11-19 : 07:23:35
|
| orjoin ext_tbl on ext_tbl.prod_code like prd_tbl.prod_code+'%'MadhivananFailing to plan is Planning to fail |
 |
|
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2009-11-19 : 07:31:57
|
quote: Originally posted by madhivanan orjoin ext_tbl on ext_tbl.prod_code like prd_tbl.prod_code+'%'MadhivananFailing to plan is Planning to fail
Really?DECLARE @ext_tbl TABLE ([prod_code] VARCHAR(255))DECLARE @prd_tbl TABLE ([prod_code] VARCHAR(255))INSERT @ext_tbl SELECT '00256'INSERT @prd_tbl SELECT 256SELECT *FROM @prd_tbl prd_tbl join @ext_tbl ext_tbl on ext_tbl.prod_code like prd_tbl.prod_code+'%' Charlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-11-19 : 07:42:05
|
quote: Originally posted by Transact Charlie
quote: Originally posted by madhivanan orjoin ext_tbl on ext_tbl.prod_code like prd_tbl.prod_code+'%'MadhivananFailing to plan is Planning to fail
Really?DECLARE @ext_tbl TABLE ([prod_code] VARCHAR(255))DECLARE @prd_tbl TABLE ([prod_code] VARCHAR(255))INSERT @ext_tbl SELECT '00256'INSERT @prd_tbl SELECT 256SELECT *FROM @prd_tbl prd_tbl join @ext_tbl ext_tbl on ext_tbl.prod_code like prd_tbl.prod_code+'%' Charlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
I thought it has leading zeroes. In this caseSELECT *, ext_tbl.prod_code ,prd_tbl.prod_codeFROM @prd_tbl prd_tbl join @ext_tbl ext_tbl on ext_tbl.prod_code*1 =prd_tbl.prod_code MadhivananFailing to plan is Planning to fail |
 |
|
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2009-11-19 : 07:47:09
|
| Interesting.Is there any performance difference between an implicit cast and an explicit one?Charlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-11-19 : 07:55:04
|
quote: Originally posted by Transact Charlie Interesting.Is there any performance difference between an implicit cast and an explicit one?Charlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
IMO, it would be same. The only difference is less typing MadhivananFailing to plan is Planning to fail |
 |
|
|
DonAtWork
Master Smack Fu Yak Hacker
2167 Posts |
Posted - 2009-11-19 : 08:15:42
|
| That, and Implicit casting = naughty.http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspxHow to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxFor ultra basic questions, follow these links.http://www.sql-tutorial.net/ http://www.firstsql.com/tutor.htm http://www.w3schools.com/sql/default.asp |
 |
|
|
|