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 8109709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:30:13+00:00 2026-06-06T01:30:13+00:00

I have a table with 3 address fields and each address field has a

  • 0

I have a table with 3 address fields and each address field has a limit of 100 characters each.

I need to create a query to make the maximum character limit for each address field to be 30 characters long. If one address field is > 30 then I’ll cut off the rest, but take the remainder and concatenate it onto the beginning of the next address field. I would do this until the last address field (address3) is filled up and then just get rid of the remainder on the last address field.

Is there a way to do this with an SQL query or with T-SQL?

  • 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-06-06T01:30:15+00:00Added an answer on June 6, 2026 at 1:30 am

    I think I’d go with the problem description, and write something that’s “obviously” correct (provided I’ve understood your spec :-))

    /* Setup data - second example stolen from Abe, first just showing that it works with short enough data */
    declare @t table (ID int not null,Address1 varchar(100) not null,Address2 varchar(100) not null,Address3 varchar(100) not null)
    insert into @t (ID,Address1,Address2,Address3)
    values (1,'abc','def','ghi'),
    (2,'abcdefghijklmnopqrstuvwxyz123456789 ', 'second part', 'third part')
    
    /* Actual query - shift address pieces through the address fields, but only to later ones */
    ;with Shift1 as (
        select
            ID,SUBSTRING(Address1,1,30) as Address1,SUBSTRING(Address1,31,70) as Address1Over,Address2,Address3
        from @t
    ), Shift2 as (
        select
            ID,Address1,SUBSTRING(Address1Over+Address2,1,30) as Address2,SUBSTRING(Address1Over+Address2,31,70) as Address2Over,Address3
        from Shift1
    ), Shift3 as (
        select
            ID,Address1,Address2,SUBSTRING(Address2Over+Address3,1,30) as Address3
        from Shift2
    )
    select * from Shift3
    

    Result:

    ID            Address1                          Address2                          Address3
    ----------- ------------------------------ ------------------------------ ------------------------------
    1           abc                                 def                                ghi
    2           abcdefghijklmnopqrstuvwxyz1234   56789 second part                 third part
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table, jos_ezrealty that has address, city, state fields and declat &
In my addresses table, I have an field named isPrimary. For each address assigned
I have a SQL table AddressCount that has 3 fields: address , state ,
I have address table in which city field have nvarchar datatype, but I want
I have this bit of JavaScript... 15 $('.ajax_edit_address').each(function() { 16 $(this).ajaxForm({ 17 target: $(this).parents('table.address').find('tr.address_header').children(':first'),
I have two table Part and SubPart. Part table has general fields like id,
I have a problem, I have table 'ip_address' with 4 fields: - id_ip -
I have a table with name varchar address varchar country varchar city varchar .....
I have a table that has 5 columns: AcctId (int), Address1 (varchar), Address2 (varchar),
I've downloaded WIPmania's worldip table from http://www.wipmania.com/en/base/ -- the table has 3 fields and

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.