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 |
vandyits
Starting Member
2 Posts |
Posted - 2006-12-04 : 11:31:25
|
I have a problem. I have two tables of serial numbers, one from accounting and one from a physical audit. I'm trying to reconcile these together and I need to find the number of matching characters from one table refrencing the other table.table1.snumber table2.snumber = number of characters that match so that I don't have to go through each line of each table and do this manually. |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-12-04 : 11:37:50
|
select isnull(pa.snumber, a.snumber) snumber,case when pa.snumber is null then 'Only in accounting table'when a.snumber is null then 'Only in physical audit table'else 'Hey! Here is a match...' end Resultfrom <physical audit table name here> pafull join <accounting table name here> a on a.snumber = pa.snumberPeter LarssonHelsingborg, Sweden |
 |
|
vandyits
Starting Member
2 Posts |
Posted - 2006-12-04 : 12:12:58
|
what i'm really trying to account for is the typo's between to two tables. I want to know how many characters are the same in the a.snumber field and pa.snumuber field to find the ones that are very similar and try to reconcile them. |
 |
|
X002548
Not Just a Number
15586 Posts |
Posted - 2006-12-04 : 12:27:00
|
This should float your boatUSE AdventureWorksGOSET NOCOUNT ONCREATE TABLE myTable99(Col1 char(10))CREATE TABLE myTable00(Col1 char(10))GOINSERT INTO myTable99(Col1)SELECT '1234567890' UNION ALLSELECT 'ZZZ4567890' UNION ALLSELECT '1234567ZZZ'INSERT INTO myTable00(Col1)SELECT '1234567890' UNION ALLSELECT 'XXX4567890' UNION ALLSELECT 'YYY4567ZZZ'GOSELECT Source, Col1 FROM ( SELECT Col1, 'MyTable99' AS Source FROM myTable99 UNION ALL SELECT Col1, 'MyTable00' AS Source FROM myTable00) AS YYYWHERE Col1 IN (SELECT Col1 FROM ( SELECT Col1 FROM myTable99 UNION ALL SELECT Col1 FROM myTable00) AS XXXGROUP BY Col1HAVING COUNT(*) = 1)GOSET NOCOUNT OFFDROP TABLE myTable99, myTable00GO Brett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxAdd yourself!http://www.frappr.com/sqlteam |
 |
|
|
|
|