i have this stored procedure to look up uk postcodes..
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[sp_postcode_UK]
-- Add the parameters for the stored procedure here
@post_code varchar(10)
AS
DECLARE @intFlag INT
SET @intFlag = 4
WHILE (@intFlag >=1)
BEGIN
SET NOCOUNT ON;
SELECT top 1 id,lat,lng from [postcodes].[dbo].UKREGIONS
where postcode = left(@post_code,@intFlag)
order by newid()
IF @@rowcount > 0
BREAK;
SET @intFlag = @intFlag - 1
END
GO
basically i havea database with the main regions and their geo positions.. so a postcode of w140df will belong to w14 in the database... sometimes it goes back to just one letter.. how do i do it so the stored procedure doesnt return blank records for the first couple of searches