Update formating

  • I'm combing a few columns into one. Here's my update statement

     

    update

    propertydetails

    set

    sr_site_addr_raw = SA_SITE_HOUSE_NBR+SA_MAIL_FRACTION+SA_MAIL_DIR+SA_MAIL_STREET_NAME+SA_MAIL_SUF+SA_SITE_POST_DIR+SA_SITE_UNIT_PRE+SA_SITE_UNIT_VAL

    from

    propertydetails where sa_property_id = sa_property_id

     

    When I select from the table it shows

    SR_SITE_ADDR_RAW

    ----------------------------------------------------------------------------------------------

    374                                   w                main street 

     

    Do I need to format it during the update to make it look like this - or should that happen during programming?

    SR_SITE_ADDR_RAW

    ----------------------------------------------------------------------------------------------

    374  W  main street 

     

     

  • What datatype are your columns?  You are either using char() or you are using varchar()

    and the application is inserting the trailing spaces.  Either way, use trim to display them without

    the trailing spaces. 

    declare @table table (house varchar(30), direction varchar(30), street varchar(30))

    insert into @table

    select '374','w','main street' union all

    select '374                 ','w                     ','main street               '

    select house + ' ' + direction + ' ' + street from @table

    select rtrim(house) + ' ' + rtrim(direction) + ' ' + rtrim(street) from @table

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply