SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Splitting A description
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

divan
Posting Yak Master

153 Posts

Posted - 01/08/2013 :  08:26:05  Show Profile  Reply with Quote
I have a table where there is a column Name Description Code and TBName when I run the following script

Select * from edit_long_code I get for example

Name Description Code TBname
LIAB_LMT $100,000 / $300,000 001 AAC_DETAIL

Is there a way I can display the description into $100,000 and $300,000 separately when I try to write a report script?

nigelrivett
Flowing Fount of Yak Knowledge

United Kingdom
3383 Posts

Posted - 01/08/2013 :  08:31:01  Show Profile  Visit nigelrivett's Homepage  Reply with Quote
select left(description,charindex('/',description)), right(description,charindex('/',reverse(description)))
from tbl

You'll probably have to subtract/add a couple to the lengths.

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

divan
Posting Yak Master

153 Posts

Posted - 01/08/2013 :  08:37:09  Show Profile  Reply with Quote
Thanks Nigelrivett your suggestion worked and I get the following result

$100,000 / / $300,000

is there anyway to get rid of the / in the display and just display

$100,000 $300,000
Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2224 Posts

Posted - 01/08/2013 :  08:56:01  Show Profile  Reply with Quote
left(description,charindex('/',description)-1), right(description,charindex('/',reverse(description))-1)


--
Chandu
Go to Top of Page

Jeff Moden
Aged Yak Warrior

USA
651 Posts

Posted - 01/14/2013 :  23:35:16  Show Profile  Reply with Quote
quote:
Originally posted by divan

Thanks Nigelrivett your suggestion worked and I get the following result

$100,000 / / $300,000

is there anyway to get rid of the / in the display and just display

$100,000 $300,000




Did you lookup CHARINDEX and REVERSE in Books Online to see how this works or are you just going to use it as a black box?

--Jeff Moden
RBAR is pronounced "ree-bar" and is a "Modenism" for "Row By Agonizing Row".

First step towards the paradigm shift of writing Set Based code:
"Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

When writing schedules, keep the following in mind:
"If you want it real bad, that's the way you'll likely get it."
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000