0

I have a variable, @RegionPeril retrieved from a cursor and I want to know if I can split this variable into two.

@RegionPeril can be the following (but not limited to):

WS EU
WS CA
EQ Worldwide
FL ROW

I want two variables: @Peril and @Region where @Peril = WS or @Peril = EQ (there can be more but it's the first two strings of the @RegionPeril variable) and @Region = EU or @Region = Worldwide (and so on...this is the 3rd string till the end of the @RegionPeril variable)

Is there any way to split this up??

Any help will be appreciated!

1
  • Good, then my answer below should work :) Commented Sep 19, 2012 at 19:28

1 Answer 1

2

Something like this should work (Assuming the first item in @RegionPeril is always 2 chars):

SELECT 
    @Region = LEFT(@RegionPeril, 2), 
    @Peril = RIGHT(@RegionPeril,LEN(RegionPeril)-3)

Or if Region can be of various lengths:

SELECT
    @Region = LEFT(@RegionPeril, CHARINDEX(' ', @RegionPeril)),
    @Peril = Right(@RegionPeril, LEN(@RegionPeril) - CHARINDEX(' ', @RegionPeril))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.