Results 1 to 3 of 3

Thread: Post Code / Zip Code Query in SQL Enterprise Manager

  1. #1
    Join Date
    Jul 2005
    Posts
    1

    Red face Post Code / Zip Code Query in SQL Enterprise Manager

    I am trying to group individuals by the Post Code area that they live in.

    In the UK, postcodes can be:

    OL10 4PZ
    M1 4AA


    I want to group by the area up until the Space.. ie:

    OL10
    M1


    Any help would be gratefully received...

  2. #2
    Join Date
    Oct 2002
    Posts
    933
    Try the MS SQL forum.

    FK

  3. #3
    Join Date
    Feb 2003
    Posts
    1,048
    Use Charindex() to find the position of the space and then use Left() to find everything up to the space.

    Select Left(PostCode, CharIndex(' ', PostCode) - 1) As PostCodeArea
    From MyTable
    Group By Left(PostCode, CharIndex(' ', PostCode) - 1)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •