convert columns to numbers and calculate % (merged 3 threads) [message #279333] |
Wed, 07 November 2007 18:45 |
labyrinth248
Messages: 14 Registered: November 2007
|
Junior Member |
|
|
hey everyone,
I am sort of new to plsql so I have a question here. I have 3 columns, the first column is a date column, the second and third columns are varchar. I need to convert the second and third columns to numbers that also count for each specific date in the first column. After this is done, I need to calculate a percentage from the second and third columns to show in a 4th column.
Thanks--
|
|
|
|
|
Re: convert columns to numbers and calculate % [message #279344 is a reply to message #279333] |
Wed, 07 November 2007 19:49 |
rleishman
Messages: 3728 Registered: October 2005 Location: Melbourne, Australia
|
Senior Member |
|
|
select col1, to_number(col2), to_number(col3), to_char(100*to_number(col2)/to_number(col2), '990.99%')
from my_table
If this isn't exactly what you wanted, consider that perhaps you could've provided a little more information. Try reading the Forum Posting Guidelines first though.
Ross Leishman
|
|
|
|
Re: convert columns to numbers and calculate % [message #279462 is a reply to message #279344] |
Thu, 08 November 2007 10:45 |
labyrinth248
Messages: 14 Registered: November 2007
|
Junior Member |
|
|
Thanks for your help Ross.
I am trying to do this in reporting services in Sql server business intelligence 2005.
I just want to take ‘dol.leak_origin_type’ and 'dol.priority’ and convert them to numbers. Then get a percent of those two columns for a new column. ‘dol.leak_origin_type’, and 'dol.priority’ will be counted based on the ‘dol.updated_dt’ column.
I am getting an invalid number error.
Here is what I have so far:
select distinct dol.updated_dt, to_number(dol.leak_origin_type), to_number(dol.priority), to_char(100*to_number(dol.leak_origin_type)/to_number(dol.leak_origin_type), '990.99%')
from dist_ord_leak_details_hdr_hst dol
Let me know if you need any more information.
Thanks
|
|
|
|
|
|
|
|
Re: convert columns to numbers and calculate % (merged 3 threads) [message #279590 is a reply to message #279524] |
Fri, 09 November 2007 04:36 |
Frank
Messages: 7901 Registered: March 2000
|
Senior Member |
|
|
labyrinth248 wrote on Fri, 09 November 2007 02:44 | Im trying to do this in toad with oracle version 9i (9.2.0.6.0)
Can anyone help with this?
Thanks
|
labyrinth248 wrote one comment before that | I am trying to do this in reporting services in Sql server business intelligence 2005.
|
Now which of the two is it?
|
|
|
Re: convert columns to numbers and calculate % (merged 3 threads) [message #279626 is a reply to message #279590] |
Fri, 09 November 2007 07:37 |
labyrinth248
Messages: 14 Registered: November 2007
|
Junior Member |
|
|
I am using both reporting services and toad. I test the code in toad then move it over to reporting services where I build the report that uses an oracle data source. For now I just want it to work in toad. When I execute the following:
---------------------------------------------------
select dol.updated_dt, to_number(dol.leak_origin_type),
to_number(dol.priority),
to_char(100*to_number(dol.leak_origin_type)/to_number(dol.leak_origin_type), '990.99%'),
dor.act_result_leak_invest
from dist_ord_leak_details_hdr_hst dol, dist_ord_rslt_leak_invest_hdr dor
-------------------------------------------------------
I get the toad error: ORA-01722: invalid number
What should I do to convert them to numbers.
Thanks
|
|
|
|
|
|
|
|
|
|
|
Re: convert columns to numbers and calculate % (merged 3 threads) [message #279687 is a reply to message #279333] |
Fri, 09 November 2007 10:57 |
labyrinth248
Messages: 14 Registered: November 2007
|
Junior Member |
|
|
I’m sorry for all of the confusion on this topic.
select distinct to_char(dol.updated_dt, 'DD') as "date",
to_number(dol.leak_origin_type), to_number(dol.priority),
to _char(100*to_number(dol.leak_origin_type)/to_number(dol.leak_origin_type), '990.99%'),
dor.act_result_leak_invest
from dist_ord_leak_details_hdr_hst dol,
dist_ord_rslt_leak_invest_hdr dor
dol.updated_dt is a date data type. dol.leak_origin_type is a varchar2 data type. dol.priority is a varchar2 data type. The data that is in the dol.leak_origin_type column only consist of “Leaks”. The only data that is in the dol.priority column consists of “Immediate”. What I want to do is convert dol.leak_origin_type and dol.priority to a number say for example ‘1’, that counts for each occurrence on dol.updated_dt.
So, whenever there is a “Leaks”, or “Immediate” on a certain date, it will add to the count on that date.
|
|
|
|