Aggregate functions and normal function in SELECT statement
hi
i am using MS Access DataBase ...
i have lot of integer coloumns in my Database
i want to retrieve the coloumn values as well as the min , max and avg of that coloumn
i dont know whether its possible to do in a single statement or not
generally if we retrieve the values of a particular coloum
we say " SELECT length FROM TABLENAME WHERE somecondition"
and then get the values as int len = rs.getInt("length")..... over a loop
but how to retieve the value of an aggregate function?
like if i say "SELECT avg(colname),max(colname),min(colname) FROM TABLENAME WHERE somecondition"
how do i retrieve this value ???
i dont know if its possible or not ....pls help.........
Give names too each column
SELECT avg(colname) average,max(colname) max,....
and then rs.getInt("average")
This works in Oracle and Sybase, not sure on MS access tough
Similar Messages
-
Excel function and ev function not working in static column key
I have created a evdre report and I notice that when I tried to use any excel function and ev functions in the static column key cell to get the value for that cell, it's not working.
e.g I have Col key define as:
ColKeyRange Sheet!&$J$12:$N$14
In K13 which is key id for time. I define is as = $K$10 where K10 is the time value from current view, it not working,the value is still K13 = $K$10. then I tried to use EVCVW function to replace K10, it also not working, but I use the same function in the description of the ID underneath, both of the are working, Any thought?
Edited by: DFW on Feb 9, 2010 7:33 PMHi,
That was exactly what I meant. They just dont work on the green ID areas or the yellow data region. Few days back even I tried that, but didnt work. So, I followed the different approach. I dont remember about the dynamic templates. Are you sure that the functions were written in the green ID region?
I remember this used to work fine in the MS version. However, in the NW version, even I am not able to make them work.
Edited by: nilanjan chatterjee on Feb 9, 2010 9:38 PM -
NVL Function and Truncate Function in Template Builder
Hi Guys,
How would I use NVL function and Truncate function in the Word Template Builder.
These functions do not work in the Query Builder when i use SQL Query as the Dataset while creating a report.
I could not find examples in the Publisher Guide either.
Thanks
rkingmduHi
How can you not use the functions in your query? Does the builder return an error? ow about just pasting your query into the report definition does the nvl/trunc work then ?
Regards
Tim
http://blogs.oracle.com/xmlpublisher -
LINQ Canonical Functions and Oracle Functions
Hello,
I am using EntityFramework (.NET 4) to access a Oracle Database (11g Express Edition Release 11.2.0.2.0 - 64bit Production).
For the most part it is working fine, but now I've stumble into a issue using LINQ Canonical Functions, that aparently are supported (see : Mapping LINQ Canonical Functions and Oracle Functions)
I am running the following expression :
var expirationDuration = 3000;
var record = Context.Table
.Where(x => x.Created.AddMilliseconds(expirationDuration) > DateTime.Now )
.FirstOrDefault();
And im getting a exception :
"LINQ to Entities does not recognize the method 'System.DateTime AddMilliseconds(Double)' method, and this method cannot be translated into a store expression."
Shouldn't AddMilliseconds be translated to (expression) + INTERVAL like the docs mentions?
Thanks for help
Regards,NunoNeither ODP.NET nor SQLClient recognizes System.DateTime AddMilliseconds(Double) method as a valid method
I would suggest you use EntityFunctions AddMilliseconds instead. -
How to : rownum and order by in select statement
Say I have a select statement with additional 'order by' clause.
The result set I want prepended by the rownum column.
But, and here comes the flaw, I want the rownum for the already ordered result set
not the unordered.
An example:
select firstname, lastname from myTable order by lastname;
When I add the rownum to the select clause,
'select rownum, firstname, lastname from myTable order by lastname;'
I might get something like:
20 Mike Adams
13 Nina Bravo
1 Tom Charlie
But I want the following result:
1 Mike Adams
2 Nina Bravo
3 Tom Charlie
I could now
'Select rownum, lastname, firstname from (select firstname, lastname from myTable order by lastname);
But I guess there is a better way!?!
which is the best way to accomplish that?
Thanks for your advice!>
'Select rownum, lastname, firstname from (select firstname, lastname from myTable order by lastname)
>
Well if you ask me there is very little difference between this query and the above query
select rownum, lastname, firstname from mytable;Because rownum is assigned before the order by. The difference is in your query you are assigning a rownum to an ordered resultset but still there is no guarantee oracle is going to read the data in an ordered fashion. In the second query rownum is assigned to an unordered resultset. Again it is the samething. So if you want to guarantee it then I will go for the following option
select row_number() over(order by lastname) rn, lastname, firstname from mytable
order by lastnameAlso check this link.
http://www.oracle.com/technology/oramag/oracle/07-jan/o17asktom.html
Regards
Raj
Edited by: R.Subramanian on Jan 13, 2009 6:20 AM -
Having trouble with using variables in functions and after functions..
Morning,
I have simplified this, as it represents the core of what’s I obviously don't know how to do.
Problem:
Say I populate that variable by reading in a list if IP addresses from file, finding the line that matches the hostname and place that string into the $IPAddress variable for use later throughout the script. I did not run into a significant problem
until I decided to convert the routine of looking up the IP address and populating the variable into a function. As soon as I made it a function, and called that function, the $IPAddress variable only had the data in it until the function completed.
Once the function had done its work, and had placed the data into the variable, I expected that “new” data to be available after the function had completed..in that variable. But it’s like the $IPAddress variable in the main script is a totally
different data then the variable with the same name that’s used within the function.
So I think this demonstrates some of what’s kicking my butt..
$IPAddress = "This is the wrong data”
Function TestFunction ()
$IPAddress #call to display the contents of the variable at the start of the function.
$IPAddress = Read-Host -Prompt "Please enter the text ‘Goober’"
$IPAddress #call to display the contents of the variable at the end of the function.
TestFunction
$IPAddress
The output I get is:
This is the wrong data
"Please enter ‘Goober’" : where I enter Goober
Goober
This is the wrong data
Huh?
I had expected:
This is the wrong data
"Please enter ‘Goober’" : where I enter Goober
Goober
Goober
What good is the repeatability of a function if it’s output is lost?THis seems to work.. IS there any reason NOT to do this?
$Global:IPAddress= "This is the wrong data” #"
Function TestFunction{
Write-Host $IPAddress-fore green
$host.ui.RawUI.FlushInputBuffer()
$Global:IPAddress =
Read-Host -Prompt
"Please enter the text ‘Goober’"
return$Global:IPAddress
TestFunction
return$Global:IPAddress -
Analytical View - Substring function and Other functions.
Hello All
I am trying to use substring and trim function for a value/string and get the field value from position 6 - 10. in analytical view.
Example: Field name XYZ (Values showing as: ASDFG GETVALUENW 2345) --> (data type :22 VARCHAR)
Output must be : GETVALUENW (which is 10 characters, from position 6 after trimming) which I am wring to new filed in Calculated coloumns.
Trying the use built-in functions but syntax wise missing some thing need your inputs.
Regards
Kiran.Hi Kiran Avunuri,
A small thought process.
Have you tried something similar(syntax) in your view.
BR
Prabhith -
Difference between Shipping function and install function in O2A
Hi,
I am asking this query from domain perspective than from technology. There are two functions in O2A namely install order and shipping function. Can anyone please explain the activities under these function.
1. Engineer takes the equipment to customer premises: Is this install order of ship function?
2. Is shipping function related to supply chain from vendor perspective and not customer perspective.
Please let me know your views. ThanksAccording to me the logic might be Shipping and Install functions are mutually exclusive. So The scenario might be like this:-
Shipping Function:-
1. Some shipping company ships the equipment to the customer and that is tracked in CSP's system that customer has received the shipment.
Install function:-
2. Customer would have confirmed some appointment date in CAF form.
3. Field Engineer will then goto the customer premises and then install the equipment. -
Group by function with CLOB fields in Select statement
I have the following sql trying to query our database. Removing the Clob field (a.description) I am successful. But I need the Clob field (a.description). Here is my current sql
select a.id_number, a.id_owner, MAX (n.next_action_required)
KEEP (DENSE_RANK LAST ORDER BY n.modified_date),
MAX (n.modified_date) KEEP (DENSE_RANK LAST ORDER BY n.modified_date)
from table1 a, table2 n
where a.id_number = n.id_number
group by a.id_number, a.id_ownerI tried the following which works sometimes but not always because the Clob field (a.description)'s length varies; anywhere from 10 characters up to 12,000 characters. I get some blanks with the following and some where text is cut off. I may not be writing the dbms_lob.substr function correct.
select a.id_number, a.id_owner, MAX (n.next_action_required)
KEEP (DENSE_RANK LAST ORDER BY n.modified_date),
MAX (n.modified_date) KEEP (DENSE_RANK LAST ORDER BY n.modified_date) , DBMS_LOB.SUBSTR (a.description, 8001, 10000)
from table1 a, table2 n
where a.id_number = n.id_number
group by a.id_number, a.id_owner, DBMS_LOB.SUBSTR (a.description, 8001, 10000)Please help. Thank you,Maybe,
but throw it away if the combination a.id_number,a.id_owner,n.next_action_required(a.id_number = n.id_number),n.modified_date(a.id_number = n.id_number) is not unique
select nd.id_number,
nd.id_owner,
nd.next_action_required,
nd.modified_date,
a.description
from (select a.id_number,
a.id_owner,
MAX (n.next_action_required) KEEP (DENSE_RANK LAST ORDER BY n.modified_date) next_action_required,
MAX (n.modified_date) KEEP (DENSE_RANK LAST ORDER BY n.modified_date) modified_date
from table1 a,
table2 n
where a.id_number = n.id_number
group by a.id_number,
a.id_owner
) nd,
table1 a
where nd.id_number = a.id_number
and nd.id_owner = a.id_owner
and nd.id_number = (select id_number
from table2
where next_action_required = nd.next_action_required
and modified_date = nd.modified_date
)Regards
Etbin -
Using sum function and round function in single text form field
Hi all,
I have a column Name - A . In the rtf template i have summed up the column A and showing it. But the output is coming as 99.9999997. I want to round it to 100.
I tried using <?round(sum(A),2)?> but dint workout.
I also tried using variables. It is also not working.. I used <?xdoxslt:set_variable($_XDOCTX,’ABS',sum(A)?> and then i used get variable to get it.... But it throwing error while using sum in the set variable step.
Can anyone please help me..
Thanks
SunilHi Sunil,
Calculate the sum into a Variable. and apply round function on the variable to get the desired value.
Calculating sum:
<?xdoxslt:set_variable($_XDOCTX,'v',xdoxslt:get_variable($_XDOCTX,'v')+DOLLARS)?> (its running sum formula,should be placed inside the table to get sum of all rows of particular column)
here Variable 'v' holds the sum value
apply round function:
<?round(xdoxslt:get_variable($_XDOCTX,'v'))?>
Thanks and Regards,
Aravind -
Output of value returned from function in SELECT statement ??
Hi
I have created the below function
create or replace
FUNCTION jc_test
RETURN VARCHAR2
IS myrec VARCHAR2(270);
BEGIN
SELECT RPAD('*',270,'*')
INTO myrec
FROM DUAL ;
RETURN myrec;
END ;
and I executed the SELECT statement in Oracle SQL developer as a script
select
LENGTH(jc_test()) len
*,jc_test() rec*
from dual ;
I get exact output as below
LEN REC
270 ******************************************************************************************************************************************************************************************************************************************************************************
So here LEN is correctly shown as 270 characters but when I see the astrisk's (also appended with spaces ) its total length is 4000 characters
Can anyone give their thoughts on this.
Its fine if I run as normal, i mean not as a script.
Regards
jc
Edited by: JC on Jun 16, 2011 11:25 AMHi,
So here LEN is correctly shown as 270 charactersYes, correct
but when I see the astrisk's (also appended with spaces ) its total length is 4000 charactersNo buts. It is not padded. That is just how it is displayed by your tool. In SQL*Plus this is controlled by LINESIZE and COLUMN
SQL> create or replace function dummy return varchar2 as begin return null; end;
2 /
Function created.
SQL> select dummy from dual;
D
X
SQL> select dummy() from dual;
DUMMY()
SQL> col "dummy()" for a10
SQL> select dummy() from dual;
DUMMY()
SQL>P.S: It is a really bad idea to create your own wrapper functions, built-in functions. Hopefully you are not really doing that?
Regards
Peter -
Calling a user defined function in a select statement
PLS-00231: function 'F_GET_PROJECT_ID' may not be used in SQL
I am caling a user defined function 'F_GET_PROJECT_ID' in a select statement and getting the above error .
Can any one help me to resolve it.
I can not replace the function with a local variable nor can I assign the output of the function to a variable and use the variable in the sql stmt. cos, the in put parameters of the function comes from the same select statement.
Please help
Thanks in advanceCan you provide your function code? Using a function like that is possible from the below example. I suspect something in your function code.
SQL> create or replace function sample_func(p_sal number)
2 return number
3 is
4 v_sal number;
5 begin
6 v_sal := p_sal+100;
7 return v_sal;
8 end;
9 /
Function created.
SQL>
SQL> select empno, ename, sal, sample_func(sal)
2 from emp
3 /
EMPNO ENAME SAL SAMPLE_FUNC(SAL)
7839 KING 5000 5100
7698 BLAKE 2850 2950
7782 CLARK 2450 2550
7566 JONES 2975 3075
7654 MARTIN 1250 1350
7499 ALLEN 1600 1700
7844 TURNER 1500 1600
7900 JAMES 950 1050
7521 WARD 1250 1350
7902 FORD 3000 3100
7369 SMITH 800 900
7788 SCOTT 3000 3100
7876 ADAMS 1100 1200
7934 MILLER 1300 1400
14 rows selected.
SQL>And yeah... your formatted code is this.
cursor c1 is
SELECT t.upi_nbr upi_nbr,
f_get_project_id(l.pay_type_code,
l.charge_type_nme,
l.charge_code) project_id,
LAST_DAY(TO_DATE(SUBSTR(t.Year_Month, 5, 2)||'/'||'01'||'/'||SUBSTR(t.Year_Month,1,4),
'MM/DD/YYYY'))reporting_period_end_date,
SUM (c.hours_worked_qty) reported_hrs
from trs.trs_timesheet@oraprod5 T,
trs.trs_line@oraprod5 L,
trs.trs_cell@oraprod5 C
where T.upi_nbr=L.upi_nbr
and T.year_month=L.year_month
and L.row_nbr=C.row_nbr
and L.upi_nbr=C.upi_nbr
and L.year_month = C.year_month
and L.invalid_activity_ind = 'V'
and rtrim(L.charge_code) is not null
AND L.Pay_Type_Code<>'REQ'
and C.Hours_Worked_Qty > 0
GROUP BY t.upi_nbr,
t.year_month,
t.oui_nbr,
l.charge_code,
l.activity_detail_code,
l.charge_type_nme,
l.pay_type_code;Cheers
Sarma. -
Function within SELECT statement
Help please...
How can I get the my custom RFCal function to work within
this select statement??
My Error:
The value SUM((a2.act_rate + a2.act_gratuity) *
ap2.actpac_quantity) cannot be converted to a number.
My Code:
SELECT outer select blah blah,
(SELECT #RFCal("SUM((a2.act_rate + a2.act_gratuity) *
ap2.actpac_quantity)" + p2.pac_serviceFee, p2.pac_occupancy)#
FROM tablep2 p2 INNER JOIN tableap2 ap2 ON p2.pac_id =
ap2.pac_id
INNER JOIN tablea2 a2 ON ap2.act_id = a2.act_id
WHERE p2.pac_id = p.pac_id) AS myTotal
FROM tablep p INNER JOIN tableap ap ON p.pac_id = ap.pac_id
INNER JOIN tablea a ON ap2.act_id = a.act_id
WHERE outer select blah blahThanks for responding Dan.
Your option of running the function on the result via a
cfloop is what I am currently doing... problem is I want to be able
to sort the function result. So with that, what would be the
simplest method?
I will test running an additional query of queries on the
result. -
1...how to find that a function module belongs to normal function module or
Hi to all.........
1...how to find that a function module belongs to normal function module or remote enabled function module?
Thanks and regards,
K.Swaminath reddyHi Swaminath,
Go to Transaction SE37.
In The Remote enabled function module, in the Attribute tab radio Button "Remote Enabled module will be selected and in the Normal Function Module, Normal Function Module will be selected.
Regards,
Mukesh Kumar -
Member /static function and procedure
hi guys,
i'm trying to figure out diffrerences between the following;
1. member function and static function
2.*member* procdure and static procedure.
i wanna know when to use them when creating an object type.thanks.hope this enlighten you
http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/objects.htm#CHDEFBEA
Maybe you are looking for
-
Downloading iTunes Without QuickTime
From the latest update from Apple to iTunes users with Windows XP, there have been many having a problem opening iTunes without receiving an error. The latest resolution posted was to download an older version of QuickTime first, and then download iT
-
Hi All, Where we need to Install the BIC Mapping Designer ???? In XI Server Or in Some Other Server is also Ok ???? Please Let me Know Regards Bopanna
-
Hello all, Does any one have the best practice/white paper doc on Industry Solutions - Insurance in BW? Or any kind of documentaion? [email protected] Thanks, Ani.
-
I'm validating and entity row in validateEntity, this validation requires compare an attribute of this entity row with an attribute of entity rows from an assoc of this entity, I obtain the childs of this row, and if the condition that I don't want t
-
Prevent android app audio playing when minimised
My android app has some looping background audio. When I minimise the app by selecting the "home" button on my Nexus 7 - the app disappears but I can still hear the audio playing. I assume the app must be still active in the background. The same app