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 |
|
cipriani1984
Constraint Violating Yak Guru
304 Posts |
Posted - 2009-05-29 : 07:05:30
|
| Hi, could anyone assist/direct how to write a query/function to retrieve the first part of the postcode?For instance: W2 3LP & NW3 4LJI am only interested in W" and NW3ThanksCipriani |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-05-29 : 07:08:13
|
| select left('w2 3lp',charindex(' ','w2 3lp'))select substring('w2 3lp',1,charindex(' ','w2 3lp')) |
 |
|
|
Lumbago
Norsk Yak Master
3271 Posts |
Posted - 2009-05-29 : 07:11:12
|
| [code]SELECT LEFT(ZIP, CHARINDEX(' ', Zip)-1), CHARINDEX(' ', Zip)FROM ( SELECT Zip = 'W2 3LP' UNION ALL SELECT 'NW3 4LJ') AS a[/code]- Lumbago |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
|
|
cipriani1984
Constraint Violating Yak Guru
304 Posts |
Posted - 2009-05-29 : 07:19:13
|
Superb, thank you!quote: Originally posted by bklr select left('w2 3lp',charindex(' ','w2 3lp'))select substring('w2 3lp',1,charindex(' ','w2 3lp'))
|
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-05-29 : 07:45:13
|
quote: Originally posted by cipriani1984 Superb, thank you!quote: Originally posted by bklr select left('w2 3lp',charindex(' ','w2 3lp'))select substring('w2 3lp',1,charindex(' ','w2 3lp'))
welcome |
 |
|
|
|
|
|
|
|