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 |
|
subhaoviya
Posting Yak Master
135 Posts |
Posted - 2012-08-08 : 05:39:26
|
| Hi, i am having table column like address shown belowADDRESS11 Abbey Drive1a Abbey Drive1b Abbey Drive2 Abbey Drive4 Abbey Drive i need to split the house number seperately from address. expecting result setHousenumber Address1 Abbey Drive1a Abbey Drive...thankssubha |
|
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2012-08-08 : 06:47:07
|
This is hard to do unless you are absolutely sure that there are no spaces in the house number. If there are none, then you can split it like this:SELECT LEFT(ADDRESS1,CHARINDEX(' ',ADDRESS1)-1) AS HouseNumber, STUFF(ADDRESS1,1,CHARINDEX(' ',ADDRESS1),'') AS ADDRESSFROM YourTable |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-08-08 : 09:45:09
|
if its always two parts you can useSELECT PARSENAME(REPLACE(Address,' ','.'),2) AS HouseNumber,PARSENAME(REPLACE(Address,' ','.'),1) AS AddressFROM Table ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2012-08-08 : 12:36:09
|
I admit it, I am biased against PARSENAME for a variety of reasons - one of which is this:CREATE TABLE #tmp ([Address] VARCHAR(255));INSERT INTO #tmp VALUES ('1973 Washington St.'), ('1973 Washington Mutual Street North')SELECT PARSENAME(REPLACE(Address,' ','.'),2) AS HouseNumber,PARSENAME(REPLACE(Address,' ','.'),1) AS AddressFROM #tmpDROP TABLE #tmp; |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2012-08-16 : 10:30:52
|
Another techniqueSELECT LEFT(ADDRESS,CHARINDEX(' ',ADDRESS)-1) AS HOUSENUMBER, SUBSTRING(ADDRESS,PATINDEX('% [^ ]%',ADDRESS),LEN(ADDRESS)) AS ADDRESSFROM #TMPMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|