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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:31:25+00:00 2026-06-12T14:31:25+00:00

I have this question for you,why would this give me the updated value with

  • 0

I have this question for you,why would this give me the updated value with the original in the same field”Ohio” that was the original…now after proc”Ohio OH” I only want the updated value.Th function returns only one value I tested it before using it in the proc. Thanks in advance for looking into it guys.

CREATE PROC [dbo].[Changestringstate] 
AS 
    UPDATE stage.statetable 
    SET    originalstatename = Rtrim(originalstatename) --avoiding trailing space issues 

    UPDATE stage.statetable 
    SET    originalstatename = Replace(originalstatename, 
                               Substring (originalstatename, 
                               Len (originalstatename) - ( 
                               Charindex(' ', Reverse( 
                               originalstatename)) ) + 1, Len(originalstatename) 
                               ), 
           dbo.Changefunction(originalstatename)) 
  • 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-12T14:31:27+00:00Added an answer on June 12, 2026 at 2:31 pm

    Consider this example

    create table statetable
    (
      originalstatename varchar(100)
    );
    insert statetable values ('ohio oh');
    GO
    
    CREATE PROC [dbo].[Changestringstate] 
    AS 
        UPDATE statetable 
        SET    originalstatename = Rtrim(originalstatename) --avoiding trailing space issues 
    
        UPDATE statetable 
        SET    originalstatename = Replace(originalstatename, 
                                   Substring (originalstatename, 
                                   Len (originalstatename) - ( 
                                   Charindex(' ', Reverse( 
                                   originalstatename)) ) + 1, Len(originalstatename) 
                                   ), 
               'ohia') 
    GO
    exec changestringstate;
    select * from statetable;
    
    --- result
    ohioohia
    

    What your proc is doing:

    The entire SUBSTRING block does one thing, which is to remove everything after the LAST SPACE. This is excluding trailing spaces, since they are trimmed off in the prior UPDATE. Examples of what it does:

    state name    |  Substring result
    Ohio OH          " OH"
    Mi Ohio OH       " OH"
    New York NY      " NY"
    

    Then comes the REPLACE block, which looks for the substring result, and replaces EVERY occurence of it with whatever comes back from dbo.Changefunction(). Let’s say it comes back with “xyz”.

    state name    |  Substring result | after replace
    Ohio OH          " OH"            | Ohioxyz
    Mi Ohio OH       " OH"            | Mixyzioxyz
    New York NY      " NY"            | New Yorkxyz
    

    Hope that helps you understand your proc, so that you can fix it accordingly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I thought this question would have already existed on SO, but then I couldn't
i have a simple question: i have this var: $v = 24000,1500,1500,1500,1500,1500,; i would
Firstly, I do not have any malicious intent out of this question. I would
This is hopefully a simple question: I have an OpenGL texture and would like
This may seem like a basic question. I have a light-weight website and would
(Sorry if it's a trivial question.) I have documents that looks like this (Python
I have searched here, GooBingHooVista'd the world and read this related question for VS
I have this question, just in theory. I do some query results and there
I have this question in which I have a SQL Server Compact Edition database
I have this question because I am not familiar latest generation of MS VS

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.