declare @CityPostCode varchar(500)
set @CityPostCode='hghgh gtr rt gtr yy'
declare @substring varchar(15)
if @CityPostCode <> ''
begin
WHILE (CHARINDEX(' ',@CityPostCode ,1)<>0)
BEGIN
SET @substring = substring(@CityPostCode ,1,CHARINDEX(' ',@CityPostCode ,1)-1)
-- Find Substring up to Separator
if (isnull(@substring,' ') <> ' ')
begin
select @substring ,1
end
SET @CityPostCode = substring(@CityPostCode ,Len(@substring)+2,Len(@CityPostCode ))
end
end
set @CityPostCode='hghgh gtr rt gtr yy'
declare @substring varchar(15)
if @CityPostCode <> ''
begin
WHILE (CHARINDEX(' ',@CityPostCode ,1)<>0)
BEGIN
SET @substring = substring(@CityPostCode ,1,CHARINDEX(' ',@CityPostCode ,1)-1)
-- Find Substring up to Separator
if (isnull(@substring,' ') <> ' ')
begin
select @substring ,1
end
SET @CityPostCode = substring(@CityPostCode ,Len(@substring)+2,Len(@CityPostCode ))
end
end
This comment has been removed by the author.
ReplyDeleteCode is not working properly..... Correct code is as below-
ReplyDeletedeclare @CityPostCode varchar(500)
set @CityPostCode='hghgh gtr rt gtr yy'
declare @substring varchar(15)
if @CityPostCode <> ''
begin
WHILE (CHARINDEX(' ',@CityPostCode ,1)<>0)
BEGIN
SET @substring = substring(@CityPostCode ,1,CHARINDEX(' ',@CityPostCode ,1)-1)
-- Find Substring up to Separator
if (isnull(@substring,' ') <> ' ')
begin
select @substring ,1
end
SET @CityPostCode = substring(@CityPostCode ,Len(@substring)+2,Len(@CityPostCode ))
end
if (isnull(@CityPostCode,' ') <> ' ')
select @CityPostCode,1
end