Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

postcode search

Status
Not open for further replies.

moleboy

IS-IT--Management
Oct 10, 2002
33
GB
Anyone,

I'm trying to search my database using the first part of the postcode to return records in an sp. The problem is when i put eh6, i get all eh6 plus eh61, eh64, etc. And when i use just eh I get no recods at all. I cant really use left due to the fact that some postcodes are only two characters like w1.

Can anyone show me any code to search for postcodes?

Cheers

Moley
 

For field = eh6
ex.
select * from mytable where left(field,3)='eh64'

For field started with 'eh'
ex.
select * from mytable where field like 'eh%'

Maybe not right,can you show how your coding look like?

 
I use this stored proc to select specific postcodes based on the first part. I believe it will fit your requirements.

Code:
CREATE PROC dbo.spPostcodePart
	@FirstPart varchar(4)
AS

DECLARE @FirstPartLen INT
SET @FirstPartLen = LEN(@FirstPart)

SELECT * FROM MyTable
WHERE LEFT(POSTCODE,@FirstPartLen+1)=@FirstPart+' '
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top