Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
Hi,I have a column with UK postcodes like thisBB9 7DLB1 4FHM28 3PLI need to select only the first part, before the space, so:BB9B1M28Thanks
dnf999
Constraint Violating Yak Guru
253 Posts
Posted - 2010-02-08 : 16:57:24
various solutions, here is one:left(postcode,charindex(' ',Postcode)-1)
Kristen
Test
22859 Posts
Posted - 2010-02-09 : 08:51:49
I would suggestleft(postcode, charindex(' ', Postcode+' ')-1)in case [postcode] doesn't contain a space
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2010-02-09 : 08:58:51
or
PARSENAME(REPLACE(Postcode,' ','.'),2)if you've only values with single part thenCOALESCE(PARSENAME(REPLACE(Postcode,' ','.'),2),PARSENAME(REPLACE(Postcode,' ','.'),1))