Results 1 to 7 of 7
  1. #1
    wutaguy is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Dec 2010
    Posts
    4

    SQL query to add avlue before and after

    I have numbers where I would like to add a fixed value before the number and a fixed value after the number. The fixed value includes spaces.
    e.g. if number is 12456, then I want the output to be H987SSS12456TSSSS, where S is space. Do i need 2 queries?

    Thanks for any help.

  2. #2
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    if the number is from a field of a table or an expression, just concat the strings before and after the field name/expression:

    e.g. select "H987SSS" & myfield &"TSSSS" from ......
    (myfield =12456)

  3. #3
    wutaguy is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Dec 2010
    Posts
    4
    Sorry, I guess I wasn't clear.

    I am importing the numbers from excel file, a total of around 50,000. I would like there to be spaces before and after, not the letter "S".

  4. #4
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    you need to do step by step:
    1 import
    2 update
    update tbl set fld="H987SSS" & fld &"TSSSS"

    replace S with space.

  5. #5
    wutaguy is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Dec 2010
    Posts
    4
    Thanks!!

    It works.

  6. #6
    wutaguy is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Dec 2010
    Posts
    4
    One more thing.
    I need the length for all rows to be 80 characters.

  7. #7
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    design the field width to 80,
    fill with spaces to 80.

    e.g. update table1 set field1=left(field1 & string(80," "),80)

Please reply to this thread with any new information or opinions.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums