parsing values in SQL w/ delimiter

Homerboy

Lifer
Mar 1, 2000
30,890
5,001
126
say my return value on a query is "Amount: $100.00" for "SALE_AMT" column.

But I only want the "100.00"
I KNOW there has to be an easy function for this in the query, but for the life of me I can not figure it out.
 
Last edited:

Homerboy

Lifer
Mar 1, 2000
30,890
5,001
126
SUBSTRING(ACTIVE.NOTE, CHARINDEX('$', ACTIVE.NOTE) + 1, LEN(ACTIVE.NOTE)) AS Test


what a pain the ass. I can't believe they don't have something like RPARSE(ACTIVE.NOTE.'my choice of characeters>) built in.
 

Homerboy

Lifer
Mar 1, 2000
30,890
5,001
126
Substring(sales_amt, 9)

I thought of that, but sadly I left out a bit of info.

"Amount?: $100.00" is a fixed width value.
So when its $100.00 there are 10 spaces between the : and the $. If it's $1000.00 there are 9 spaces...
 

WannaFly

Platinum Member
Jan 14, 2003
2,811
1
0
Similar to your other thread if it's always "AMOUNT: " then use replace. If you must use 3 replaces, one for "AMOUNT:" one for "$" and one for all spaces.
 

Homerboy

Lifer
Mar 1, 2000
30,890
5,001
126
Similar to your other thread if it's always "AMOUNT: " then use replace. If you must use 3 replaces, one for "AMOUNT:" one for "$" and one for all spaces.

Oh I like that solution too! sneaky.:ninja:

As I get more and more into SQL and more elaborate reports/queries, that is one thing I like about it; there's always a dozen ways to do 1 thing... each better than the next.
 

Homerboy

Lifer
Mar 1, 2000
30,890
5,001
126
yeap. I'm familiar with "RIGHT", and have used it on a few occasions.
Thanks.
 

beginner99

Diamond Member
Jun 2, 2009
5,320
1,768
136
SUBSTRING(ACTIVE.NOTE, CHARINDEX('$', ACTIVE.NOTE) + 1, LEN(ACTIVE.NOTE)) AS Test


what a pain the ass. I can't believe they don't have something like RPARSE(ACTIVE.NOTE.'my choice of characeters>) built in.

Or one could say its retarded to store "Amount?: $100.00". Not your fault but the guy that came up with this idea sure didn't understand what a relational database is.
It's like driving your car into a river and then wonder why it doesn't float.
Excel freaks are a PITA.
 

ForumMaster

Diamond Member
Feb 24, 2005
7,792
1
0
Similar to your other thread if it's always "AMOUNT: " then use replace. If you must use 3 replaces, one for "AMOUNT:" one for "$" and one for all spaces.

A better way is this:

substring is a functions that requires as input:
that column
from where to begin
where to end

if you use 3 replaces each time on the column, that's 3 additional function calls.
it adds overhead.

the preferred method is this: using instr (a function that returns the position of a string in another string). it requires as input a column and the string to find.


an example:

substr(active.note,instr(active.note,'$')+1)

that's it. you don't have to provide the third parameter for substr if you want the rest of the string (length of column).