Trim excess characters in SQL

I have a SQL report that has a field based on a query.  The Question is
"Current/Prior Military Service"  answer is Y or No,  if yes, which war.

When I run the report it prints out as the following:
{N|}
{N|}
{Y|}
{N|}
{Y|}
{N|}
{N|}
{N|}
{N|}
{N|Desert Storm}
{N|}
{N|}
{Y|}
{N|}
{N|}
{N|}

I used the following code to TRIM the field to separate into two columns but how do I get rid of the leading and trailing characters and leave only the Name of the war in the second column.  This is code I used:
RTRIM(RAQ_R.ValueInfo   ) as CurrentPriorMilitaryService,
LTRIM(    RAQ_R.ValueInfo) as NameOfWar

Here are the results after the TRIM:
CurrentPriorMilitaryService       NameOfWar
{N|}                                            {N|}
{Y|Desert Storm}                       {Y|Desert Storm}
{N|}                                            {N|}

i NEED IT LIKE THIS
 CurrentPriorMilitaryService        NameOfWar
N
Y                                                Dessert Storm
N
kvrogersAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Aneesh RetnakaranDatabase AdministratorCommented:
select Substring(RAQ_R.ValueInfo,2,1)CurrentPriorMilitaryService        , case when len(RAQ_R.ValueInfo) > 4 THEN SUBSTRING(RAQ_R.ValueInfo, Charindex('|',RAQ_R.ValueInfo)+1, CHARINDEX('}',RAQ_R.ValueInfo)-Charindex('|',RAQ_R.ValueInfo)-1 )  else '' end NameOfWar
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kvrogersAuthor Commented:
Thank you for your quick response.  I will keep this reference in my book.
0
kvrogersAuthor Commented:
I have a similar field in another report that has a response of {Y|} that I need to just say  Y.
Here is what I entered:
Substring(RAQ_R.ValueInfo,2,1)HxInfectiousDisorder        , case when len(RAQ_R.ValueInfo) > 4 THEN SUBSTRING(RAQ_R.ValueInfo, Charindex('|',RAQ_R.ValueInfo)+0, CHARINDEX('}',RAQ_R.ValueInfo)-Charindex('|',RAQ_R.ValueInfo))  else '' end  Response

and my report shows

HxInfectiousDisorder           Response

Y
Y
Y

Can you break down the substring for me and show me how to just use a single response.  I tried to edit it but when I did then I got NO response at all.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Aneesh RetnakaranDatabase AdministratorCommented:
case when len(RAQ_R.ValueInfo) > 4
  change that to case when len(RAQ_R.ValueInfo) >= 4
0
kvrogersAuthor Commented:
I entered:  
Substring(RAQ_R.ValueInfo,2,1)HxInfectiousDisorder        , case when len(RAQ_R.ValueInfo) >= 4 THEN SUBSTRING(RAQ_R.ValueInfo, Charindex('|',RAQ_R.ValueInfo)+0, CHARINDEX('}',RAQ_R.ValueInfo)-Charindex('|',RAQ_R.ValueInfo))  else '' end  

Here is what I get now.   I need to get rid of last column.
HxInfectiousDisorder      Response
Y                                         |
Y                                         |
Y                                         |


I just want it to say:  
HxInfectiousDisorder
Y
Y
Y
0
Aneesh RetnakaranDatabase AdministratorCommented:
you just need to use this , you can skip the rest of your query

Substring(RAQ_R.ValueInfo,2,1)HxInfectiousDisorder
0
kvrogersAuthor Commented:
Thanks, that worked.  I should have made this a new question and given you more points.  I will ask what to do.
0
Aneesh RetnakaranDatabase AdministratorCommented:
that's fine. Glad I helped.
0
kvrogersAuthor Commented:
I sent an email to the moderator to see what I could do.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.