| Author |
Topic |
|
sqlchiq
Posting Yak Master
133 Posts |
Posted - 2008-08-19 : 12:23:59
|
| I have a column that look like thisSeptember 13 US$ 1430.00 - September 14 US$ 1430.0August 20 US$ 1700.00 - August 21 US$ 1700.00 - AuIs there a way to return only1430.001700.00etc etc |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-08-19 : 12:30:07
|
if the format is consistent, you could try the belowSELECT SUBSTRING(Col,CHARINDEX('$',Col)+2,(CHARINDEX('-',Col)-1)-CHARINDEX('$',Col))FROM YourTable |
 |
|
|
sqlchiq
Posting Yak Master
133 Posts |
Posted - 2008-08-19 : 12:40:06
|
quote: Originally posted by visakh16 if the format is consistent, you could try the belowSELECT SUBSTRING(Col,CHARINDEX('$',Col)+2,(CHARINDEX('-',Col)-1)-CHARINDEX('$',Col))FROM YourTable
Msg 536, Level 16, State 5, Line 1Invalid length parameter passed to the SUBSTRING function. |
 |
|
|
sqlchiq
Posting Yak Master
133 Posts |
Posted - 2008-08-19 : 12:41:48
|
| there are also rates that are normal in this column.790.00810.00815.00in addition to the ones that are messed up, maybe that has something to do with it |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-08-19 : 12:43:53
|
ok. then alter it like thisSELECT SUBSTRING(Col,CASE WHEN CHARINDEX('$',Col)>0 THEN CHARINDEX('$',Col)+2 ELSE 1 END,CASE WHEN CHARINDEX('-',Col)>0 THEN (CHARINDEX('-',Col)-1)-CHARINDEX('$',Col) ELSE LEN(Col) END)FROM YourTable |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-08-19 : 12:54:54
|
| what all are possible formats of data in your column? |
 |
|
|
sqlchiq
Posting Yak Master
133 Posts |
Posted - 2008-08-19 : 13:01:27
|
quote: Originally posted by visakh16 what all are possible formats of data in your column?
Was able to fix it, just had to alter some of the stuff in your select, thank you visakh! |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-08-19 : 13:04:07
|
quote: Originally posted by sqlchiq
quote: Originally posted by visakh16 what all are possible formats of data in your column?
Was able to fix it, just had to alter some of the stuff in your select, thank you visakh!
You're welcome |
 |
|
|
|