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 |
|
tooba
Posting Yak Master
224 Posts |
Posted - 2011-06-15 : 21:24:07
|
| Here is my sourceTable1ID ADDR1 21345 NORWAL BLVDTable2ID ADDR7 21345 NORWALMy question is I want to update my Table.ID and here is my only link ADDR. I am using this update syntax UPDATE HG2 SET ID = HG1.IDFROM HG2INNER JOIN HG1ON HG1.ADDR = HG2.SUBSTRING(ADDR,1,(LEN(ADDR) - LEN(LTRIM(RTRIM(REVERSE(SUBSTRING(REVERSE(ADDR),1,charindex(REVERSE(ADDR),' ',1))))))))Basically I am trying to trim BLVD from TABL1 and try to link to Table2.ADDR and update Table2.ID 7 to Table.ID 1. Please let me where I am doing wrong. Thanks in advance. |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2011-06-16 : 09:37:30
|
| If all you're trying to do is remove 'BLVD' from the string in HG2.ADDR tryHG1.ADDR = REPLACE(HG2.ADDR,'BLVD','')JimEveryday I learn something that somebody else already knew |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2011-06-16 : 09:41:29
|
Don't if it will work but change thisON HG1.ADDR = HG2.SUBSTRING(ADDR,1,(LEN(ADDR) - LEN(LTRIM(RTRIM(REVERSE(SUBSTRING(REVERSE(ADDR),1,charindex(REVERSE(ADDR),' ',1))))))))to thisON HG1.ADDR = SUBSTRING(ADDR,1,(LEN(HG2.ADDR) - LEN(LTRIM(RTRIM(REVERSE(SUBSTRING(REVERSE(HG2.ADDR),1,charindex(REVERSE(HG2.ADDR),' ',1)))))))) No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
tooba
Posting Yak Master
224 Posts |
Posted - 2011-06-16 : 21:04:24
|
| That is just a sample data, i want to remove all Street suffix to just link HOuse# and Street Name, Let me try that "webfred" suggest. Thank you guys. |
 |
|
|
tooba
Posting Yak Master
224 Posts |
Posted - 2011-06-16 : 21:31:19
|
| Awesome its work fine, Thanks for your help. |
 |
|
|
|
|
|
|
|