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

The Archive Base Latest Questions

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

I do have this situation I am trying to use if else for the

  • 0

I do have this situation I am trying to use if else for the following .It does work but it doesnt work as expected..when there is nothing choosen for the preState it will bring Null I want it to display for each choices.Could you please have a look at it.Thanks guys..something is wrong with my if….”you can copy and run it it”

       DECLARE     @returnvalue VARCHAR(50)
        ,@state VARCHAR(50)
        ,@i INT
        ,@postState  VARCHAR(50)
        ,@preState  VARCHAR(50)
        ,@Anystring  VARCHAR(255)
        ,@state1 VARCHAR(50)
        ,@state2 VARCHAR(50)

        SET @Anystring='IA all the states Colorado '

      SELECT @state =LTRIM((RTRIM(SUBSTRING(@Anystring, LEN(@Anystring) -      CHARINDEX(' ', REVERSE(@Anystring))+1 , LEN(@Anystring)))))

         SET @state =REPLACE(REPLACE(@Anystring, '.', ' '), '&', ' ')

         set @state1=@state


  SET @i = CHARINDEX(' ',@state1 )

  If (@i > 0 and SUBSTRING(@state1, 1, @i-1) IN ('IA','CO','Iowa','Colorado'))
     begin
     SELECT  @preState = RTRIM(SUBSTRING(@state1, 1, 1)), 
             @state1 = LTRIM(SUBSTRING(@state1, @i+1, 999))
     end

   else IF (@i > 0 and SUBSTRING(@state, 1, @i-1) IN ('DC','SEA','NY'))
     begin
     SELECT  @preState = RTRIM(SUBSTRING(@state1, 1, 2)), 
             @state1 = LTRIM(SUBSTRING(@state1, @i+1, 999))

     end        


   SET @i = LEN(@state1) - CHARINDEX(' ', REVERSE(rtrim(@state1)))
  IF (@i > 0 and @i < LEN(@Anystring) and SUBSTRING(@state1, @i+2, 999) IN     ('IA','CO','Iowa','Colorado')) 
      begin
     SELECT @postState = SUBSTRING(@state1, @i+2, 1),
             @state1 = RTRIM(SUBSTRING(@state1, 1, @i))
      end       

else IF (@i > 0 and @i < len(@state)  and SUBSTRING(@state1, @i+2, 999) IN ('DC','SEA','NY')) 
    begin
     SELECT @postState = SUBSTRING(@state1, @i+2, 2),
             @state1 = RTRIM(SUBSTRING(@state1, 1, @i))
    end         

else IF (@i > 0 and SUBSTRING(@state1, 1, @i-1) IN ('','  ','   '))  
        begin

        SELECT @postState = '',
             @state1 = LTRIM(SUBSTRING(@state1, 1, 999))          
        end           
      SET  @state1=@preState+' ' + @state1+' '+@postState 

      set @state2=@state1


      select @state2
  • 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-12T11:18:32+00:00Added an answer on June 12, 2026 at 11:18 am

    If you mean the you get NULL from

    SET  @state1=@preState+' ' + @state1+' '+@postState 
    

    Then you will want to ISNULL it to handle the lack of prefix

    SET  @state1= isnull(@preState+' ','') + @state1+' '+@postState 
    

    Same for @poststate

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

Sidebar

Related Questions

I'm trying to figure out how to handle this situation. I have the following
This is probably a shot in the dark, but does anyone else use Fortis
I have this situation: $(#button).toggle(function(){ $(#window).animate({top:'0%'},1000); },function(){ $(#window).animate({top:'-100%'},1000); }); but I need change it
I have this situation: There are a login page with a login form (form
I have a problem trying to solve a situation, when I use Java Reflection
I think I have understood how MeasureOverrride works, but I am trying to use
I have been trying to use nextAll() and siblings() but those functions never return
I have this situation: http://jsfiddle.net/bRDgK/3/ In this situation I have a modal dialog with
I have this situation: { float foo[10]; for (int i = 0; i <
I have this situation where I want to display a list of Administration objects

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.