Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3230422
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:55:31+00:00 2026-05-17T16:55:31+00:00

I am supposed to remove the following from the address field. Replace all words

  • 0

I am supposed to remove the following from the address field.

  1. Replace all words named as ‘Flat’ to empty space, also remove the number that comes along with it.

eg. I have word called as ‘Flat 234 5th Street’.

It should be replaced as 5th Street.

I gave the query as

select   
    ltrim(rtrim( substring ('Flat 123 5th Street', charindex('Flat ','Flat 123 5th Street') + 5, len ('Flat 123 5th Street'))))

It returned

123 5th Street

Now I have to find whether till the next occurrence of space, I have a numeric value or not.

If Numeric, then remove it, else leave it .

Can anyone help please.

Regards,
Hema

Yes Marc_S, i should have done it (edited).
I can not do in any other language. Supposed to do in T-SQL only.

Hi LittleBobbyTales, Thanks for the Answer.
Actually its not a standard format, I might have only
Flat 123

or Flat 123 5th Street 1st Main Road

or 1st Main Flat 1

There is no rule that we will have 1 numbers or 2 numbers after the word Flat.
There may or may not be numbers at all.

It can be either way.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T16:55:31+00:00Added an answer on May 17, 2026 at 4:55 pm

    You could use a scalar-valued function to strip the flat part out. The tricky part is how to check if a word is a number: @word like '%[^0-9]%' does that by looking for a character that is not 0-9. Full example:

    if OBJECT_ID('fn_StripFlat') is not null
        drop function fn_StripFlat
    go
    create function dbo.fn_StripFlat(
        @street varchar(150))
    returns varchar(150)
    as begin
        declare @word varchar(150)
        declare @result varchar(150)
        declare @cur int
        declare @next int
        declare @in_flat bit
    
        set @cur = 1
        while 1=1
            begin
            set @next = CHARINDEX(' ', @street, @cur)
            if @next = 0
                set @word = SUBSTRING(@street, @cur, len(@street) - @cur + 1)
            else
                set @word = SUBSTRING(@street, @cur, @next - @cur)
    
            if @word = 'flat'
                begin
                set @in_flat = 1
                end
            else if @word like '%[^0-9]%'
                begin
                set @in_flat = 0
                set @result = IsNull(@result + ' ','') + @word
                end
    
            if @next = 0
                break
            set @cur = @next + 1
            end
        return IsNull(@result,'')
    end
    go
    

    Test code:

    declare @Streets table (street varchar(150))
    insert @Streets
              select 'Flat 234 5th Street'
    union all select 'Flat 123 456 5th Street 1st Main Road'
    union all select '1st Main Flat 1'
    union all select '5th Street 1st Main Road'
    union all select 'FlatStreet'
    union all select ''
    
    select  street
    ,       dbo.fn_StripFlat(street)
    from    @Streets
    

    This prints:

    Flat 234 5th Street                     5th Street
    Flat 123 456 5th Street 1st Main Road   5th Street 1st Main Road
    1st Main Flat 1                         1st Main
    5th Street 1st Main Road                5th Street 1st Main Road
    FlatStreet                              FlatStreet
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I suppose I could take a text and remove high frequency English words from
I know that when you add/change/remove methods in a COM interface you're supposed to
I want to remove a suppose control whose type is of border, from the
Supposed I have the following string: string str = <tag>text</tag>; And I would like
I want to use XSL to remove some elements from a tree. Suppose I
This must be a misunderstanding from my side, but I have the following: I
Removed link, problem solved The menu at the top is supposed to be a
Is there any Visual Studio Add-In that can do the remove method refactoring? Suppose
Supposed I have a class called TrafficLight and I would like to have a
I'm experiencing problems with the :with clause in the following code. -counter.times do |c|

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.