Finding minimum value in each row using dynamic query
need to find the minimum and maximum value from each row using dynamic query
[from curr] will be given as input
Tuky
DECLARE @t TABLE(a INT,b INT,c INT);
INSERT @t VALUES(1,2,3),(9,8,7),(4,6,5);
SELECT *
, ( SELECT MAX(val)
FROM (VALUES (a)
, (b)
, (c)
) AS value(val)
) AS MaxVal
, ( SELECT MIN(val)
FROM (VALUES (a)
, (b)
, (c)
) AS value(val)
) AS MinVal
FROM @t;
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence
Similar Messages
-
How to find a data with the minimum value I get without using sub query
Currently, I manage to get a record by using subquery to find the minimum number, eg:
SELECT TAccTrn.ASysCde
FROM TAccTrn
WHERE TAccTrn.AAccTrnNum=(SELECT Min(TAccTrn.AAccTrnNum)
FROM TAccTrn, TDbtSchCltDtl
WHERE TDbtSchCltDtl.ASrcRefId=TAccTrn.ASrcRefId
AND TDbtSchCltDtl.ASrcRefSubId=TAccTrn.ASrcRefSubId
AND TDbtSchCltDtl.ASrcRefSeq=TAccTrn.ASrcRefSeq)
Is there any more idea without using the subquery?Hi ,
What about using an in-line view and the row_number () analytic function...????
Here is an example....
SQL> select * from emp;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7369 SMITH CLERK 7902 18/12/1980 800,00 20
7499 ALLEN SALESMAN 7698 20/02/1981 1600,00 300,00 30
7521 WARD SALESMAN 7698 22/02/1981 1250,00 500,00 30
7566 JONES MANAGER 7839 02/04/1981 2975,00 20
7654 MARTIN SALESMAN 7698 28/09/1981 1250,00 1400,00 30
7698 BLAKE MANAGER 7839 01/05/1981 2850,00 30
7782 CLARK MANAGER 7839 09/06/1981 2450,00 10
7788 SCOTT ANALYST 7566 18/04/1987 3000,00 20
7839 KING PRESIDENT 17/11/1981 5000,00 10
7844 TURNER SALESMAN 7698 08/09/1981 1500,00 0,00 30
7876 ADAMS CLERK 7788 21/05/1987 1100,00 20
7900 JAMES CLERK 7698 03/12/1981 950,00 30
7902 FORD ANALYST 7566 03/12/1981 3000,00 20
7934 MILLER CLERK 7782 23/01/1982 1300,00 10
14 rows selectedUsing a solution like the one you don't want ...(a subquery) i would write....
SQL> select ename from emp
2 where hiredate=(select min(hiredate) from emp)
3 /
ENAME
SMITHWhereas , using an in-line view....
SQL> select ename from
2 (
3 select ename,row_number() over(order by hiredate asc) row_num from emp
4 )
5 where row_num=1
6 /
ENAME
SMITHIs it acceptable...????
Regards,
Simon -
Finding minimum value from spreadsheet
Hi,
I am attaching here my spreadsheet. In that spreadsheet I want to find minimum value of column B and display the corresponding value at the same iondex from column A.
Attachments:
vna_readings.xlsx 14 KBHi jyotia,
in this thread you'll find the functions to read the entire content from your excel file. If you have your data as an array in LabVIEW, then you can use the "Array Min&Max" function to get the min index from your column "B". With index array you can read the corresponding value from column "A".
Mike -
How to retrive KFF segment values in each row of VO?
Hi,
I need to retrve Special Information Type values in HR screen.
There is a table based on the VO and on of the column is a flex (KFF) linked ot the same VO.
How can i retrieve the KFF segments values from each row of the table (or VO row).
The VO contains the ID_FLEX_NUM only.
Specific issue details:
It is an HR screen
page : PersonSIT Page
Region : SpecialInformationType(Table)
VO : SpecialInformationDetailsVO
flex id="HrSitKeyFlex" flexName="PEA" flexFieldAppShortName="PER" user:akAttributeCode="HR_PERSON_SIT_FLEX"
Any information is of great help
Thanks,
Kamath..Vo Query is
SELECT /*+ ORDERED */pac.analysis_criteria_id,
ppa.analysis_criteria_id old_analysis_criteria_id,
ppa.person_analysis_id,
ppa.object_version_number,
ppa.id_flex_num,
ppa.business_group_id,
ppa.person_id,
ppa.date_from,
ppa.date_to,
'DB_ROW' status,
ppa.date_from old_date_from,
ppa.date_to old_date_to,
ppa.attribute1,
ppa.attribute2,
ppa.attribute3,
ppa.attribute4,
ppa.attribute5,
ppa.attribute6,
ppa.attribute7,
ppa.attribute8,
ppa.attribute9,
ppa.attribute10,
ppa.attribute11,
ppa.attribute12,
ppa.attribute13,
ppa.attribute14,
ppa.attribute15,
ppa.attribute16,
ppa.attribute17,
ppa.attribute18,
ppa.attribute19,
ppa.attribute20,
ppa.attribute_category
FROM per_person_analyses ppa,
per_analysis_criteria pac
WHERE ppa.business_group_id = :1
AND ppa.person_id = :2
AND ppa.id_flex_num = :3
AND pac.analysis_criteria_id = ppa.analysis_criteria_id
The values from log file for a single row is as below
i = 0
row.getAnalysisCriteriaId()=68198
row.getAttribute1()=null
row.getAttribute10()=null
row.getAttribute11()=null
row.getAttribute12()=null
row.getAttribute13()=null
row.getAttribute14()=null
row.getAttribute15()=null
row.getAttribute16()=null
row.getAttribute17()=null
row.getAttribute18()=null
row.getAttribute19()=null
row.getAttribute20()=null
row.getAttribute2()=null
row.getAttribute3()=null
row.getAttribute4()=null
row.getAttribute5()=null
row.getAttribute6()=null
row.getAttribute7()=null
row.getAttribute8()=null
row.getAttribute9()=null
row.getAttributeCategory()=null
row.getBusinessGroupId()=83
row.getDateFrom()=2009-10-01 03:32:38.0
row.getDateTo()=null
row.getIdFlexNum()=50454
row.getPersonAnalysisId()=null
row.getObjectVersionNumber()=null
row.getOldAnalysisCriteriaId()=null
row.getOldDateTo()=null
row.getOldDateTo1()=null
row.getPersonId()=46788
row.getSelectFlag()=Y
row.getStatus()=NEW_ROW
Here, row.getIdFlexNum()=50454 is the id_flex_num- KFF structure code which has 4 segments.
I need to get the value for the VaueSet of Segment1
The segment values are displayed in the OAF page but i did not get how did std oracle code fetch it
Thanks,
kamath -
How to set Dropdown list in tablen whith others Dropdown values in each row
how to set Dropdown list in tablen whith others Dropdown values in each row of the table
hi ,
You have to add the parent element before adding data to the child node ...you follow the below steps it will work
1) Take ContextStructure as follows ...
tabledata (valuenode)
ddownbyindex( value node) --within the tabledata node
value (attribute)
2)Binding to your layout
tabledata (node) ---bind this to the dataSource property of your table
ddownbyindex( node)
Value (attribute)--bind to the texts property of you DDbyIndex
3)In wdinit() method add the following code
IPrivate<Your view name>.ITabledataElement tabledataElement =wdContext.createTabledataElement();
wdContext.nodeTabledata().addElement(tabledataElement);
for(int i=0;i<5;i++)
IPrivate<Your viewname>.IDdownbyindexElement ddbyindexElement=wdContext.createDdownbyindexElement();
ddbyindexElement.setValue("Value"+i);
wdContext.nodeDdownbyindex().addElement(ddbyindexElement);
And set the cardinality property of the table node as 0..n
and dropdownbyinex node to 1..n
You try it ...
Regards
Madhavi
Edited by: madhavi kotra on Sep 2, 2008 6:00 PM -
Converting rows to columns using dynamic query.
I am trying to use the below code that I founnd on the web to conver rows to columns. the reason that I want to use dynamic query is that the number of rows are not know and changes.
declare
lv_sql varchar2(32767) := null ;
begin
lv_sql := 'SELECT Iplineno ';
for lv_rec in (SELECT distinct vendor from bidtabs where letting = '10021200' and call ='021')
loop
lv_sql := lv_sql
|| CHR(10)
|| ', MAX( DECODE( vendor, '
|| chr(39)
|| lv_rec.vendor
|| CHR(39)
|| ', bidprice, NULL ) ) as "'
|| lv_rec.vendor
|| '" ' ;
end loop;
lv_sql := lv_sql
|| CHR(10)
|| 'FROM bidtabs where letting = ''10021200'' and call = ''021'' and lineflag = ''L'' '
|| CHR(10)
|| 'GROUP BY iplineno ;' ;
here is the result
BIDPRICE CALL IPLINENO LETTING VENDOR
9,585 021 0010 10021200 C0104
1,000 021 0020 10021200 C0104
1,000 021 0030 10021200 C0104
17 021 0040 10021200 C0104
5 021 0050 10021200 C0104
11,420 021 0010 10021200 K0054
1,100 021 0020 10021200 K0054
1,100 021 0030 10021200 K0054
5 021 0040 10021200 K0054
3 021 0050 10021200 K0054
8,010 021 0010 10021200 V070
900 021 0020 10021200 V070
1,320 021 0030 10021200 V070
11 021 0040 10021200 V070
3 021 0050 10021200 V070
and here is the desired output
CALL IPLINENO LETTING C0104 K0054 V070
021 0010 10021200 9,585 11,420 8,010
021 0020 10021200 1,000 1,100 900
021 0030 10021200 1,000 1,100 1,320
021 0040 10021200 17 5 11
021 0050 10021200 5 3 3Here is the error message I am getting:
RA-06550: line 22, column 43:
PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following:
begin case declare end exception exit for goto if loop mod
null pragma raise return select update while with
<an identifier> <a double-quoted delimited-identifier>
<a bind variable> << close current delete fetch lock insert
open rollback savepoint set sql execute commit forall merge
pipe -
How to use dynamic query for Result table
Hello Experts,
I want to use dynamic query and then display the result in the assignment block.
Using dynamic query BTQAct and BTQRAct and base on some search criteria i want tofilter and then append the result in the result table of that custom context node, and then it should display the result in the view in UI.
SO can you please provide me the samplle code on how to use the dynamic query and append in the result table.
Regards.Hi,
Please find below sample code:
data: query TYPE REF TO cl_crm_bol_dquery_service,
result TYPE REF TO if_bol_bo_col.
DATA: lt_params TYPE crmt_name_value_pair_tab,
lwa_params TYPE crmt_name_value_pair.
query = cl_crm_bol_dquery_service=>get_instance( 'BTQAct' ). " Get instance of dynamic query
Set general query parameter for maximum number of hits
lwa_params-name = 'MAX_HITS' .
lwa_params-value = '50'.
APPEND lwa_params TO lt_params.
query->set_query_parameters( it_parameters = lt_params ).
query->add_selection_param( iv_attr_name = 'OBJECT_ID'
iv_sign = 'I'
iv_option = 'EQ'
iv_low = <lv_objectid>
iv_high = '' ). " Set your search criteria. Repeat this code if you have multiple parameters
"You can find possible search options for a query object in GENIL_BOL_BROWSER
result ?= query->get_query_result( ). " Get result from your search query
me->typed_context-> <your result context node>->set_collection( result ).
Here you will have to create a context node in your view which would refer to query result object like for BTQAct its BTQRAct
Hope this helps.
e Regards,
Bhushan -
How to use three part name with using dynamic query.
Dear all, (sqlserver 2008 express r2)
q1)following is showing error, is it possible to accomplish the task with out using dynamic query.
DECLARE @A VARCHAR(100)
DECLARE @A1 VARCHAR(100)
SET @A='DB1'
SET @A1='DBO'
SELECT * FROM @[email protected]
q2) table value function is not accepting dynamic query , is there any way to do this task.
yours sincerleyCertain parts in an SQL query like FROM tablename cannot be local variables. In such a case, dynamic SQL can be applied:
http://www.sqlusa.com/bestpractices/dynamicsql/
As noted above, more information needed to decide if dynamic SQL the correct solution in this instance.
Kalman Toth Database & OLAP Architect
SQL Server 2014 Design & Programming
New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012 -
Dynamic messageChoice based on value in each row
Hi All,
Am trying to implement a requirment, am not sure how i can acchive this in OAF.
I would appriciate any one who points me in the right direction
How to have a dynamic messageChoice in OAFTable.
My scenario is like this,
OAFTable[UI Table]
========================================
| Name | xxx | MessageChoice values |
========================================
| 12-A | xxx | Apple,Airport |
| 15-B | xxx | Ball,Box |
| 20-S | xxx | Singapore |
=======================================|
VALUE_TABLE[DB table]
=======================
| Letter | Value |
=======================
| A | Apple |
| S | Singapore |
| A | Airport |
| B | Ball |
| B | Box |
=======================
There is a messageChoice column in my OAFTable(third column as represented above),
values for this messageChoice should be filtered on 'Name' column in each row i.e extract the letter and use this extracted value to filter the values in VALUE_TABLE.
Where clause for each rows message choice should dynamically modify as
Row 1 : select value from VALUE_TABLE where letter = 'A'
Row 2 : select value from VALUE_TABLE where letter = 'B'
Row 3 : select value from VALUE_TABLE where letter = 'C'
since messageChoice EVENT is generated only after value is changed, i cann use that to modify the where clause of the VO.
Is there any feature in OAF that modifyes VO's WHERE clause for each row?
what will be the ideal approach to acchive this. surely some one would have resolved this kind of scenario..
Advance thanks for any suggestions :)
srinathHi,
Yes there is a standard approach available
Consider a container, such as a table, that has two columns. One column displays a department, while the
other column displays all the employees of that department in a poplist. The view object used for the poplist
(Pick List View Definition) needs the department number (the "Deptno" field of the container) bound for bind
variable :1. This can be done with the following code example in the controller's processRequest method:
OATableBean table = ...
OAMessageChoiceBean empPoplist =
(OAMessageChoiceBean)table.findChildRecursive("EmpName");
empPoplist.setListVOBoundContainerColumn(0, /* bind index */
table,"Deptno");
This code binds the first (0th) bind index of the employee poplist view object to the value displayed by the
column named Deptno in the table.
The method setListVOBoundContainerColumn can be called multiple times if the query used for the poplist has
multiple bind variables. Note that this approach effectively simulates a BC4J view link except that it relies on
the UI table columns for the bind values rather than the view object attribute values directly.
Thanks,
Gaurav -
How to save values form all row in dynamic table into mysql database?
hello guys..
i got some problem on developing expert system using adobe dreamweaver and mysql.
i've create a dynamic table and have some value from different row. i want to save values from all row to mysql database.. unfortunately.. i'm failed to do that.. for now, i just can save value from first row.
kindly you can help me to solve this problem.. or maybe there is any tutorial i can follow..
thank you in advance.
this is my script for dynamic table
<table border="1" cellpadding="1" cellspacing="1">
<tr>
<td>namaSoalan</td>
<td>jaw</td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_Recordset1['namaSoalan']; ?></td>
<td><label for="9"></label>
<select name="9" id="9">
<option value="value" <?php if (!(strcmp("value", $row_Recordset1['namaSoalan']))) {echo "selected=\"selected\"";} ?>>sila</option>
<option value="" <?php if (!(strcmp("", $row_Recordset1['namaSoalan']))) {echo "selected=\"selected\"";} ?>>ya</option>
<option value="0" <?php if (!(strcmp(0, $row_Recordset1['namaSoalan']))) {echo "selected=\"selected\"";} ?>>tidak</option>
</select>
<label for="u"></label></td>
</tr>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table>dear bregent and SnakEyez02.
i have create 2 table, which is soalan table and temporary table.
user will answer all the question. either 'ya' or 'tidak'..
each answer have different value..
this value store permanently in soalan table..
this value i want save to temporary table too.
for now, i success only save for the first row but i want save for all..
anybody please help me.. -
Table control list box. different values in each row of the list box
Hi all,
i have a requirement to display text box in table control. Each row of list box should contain different values.
i tried with the below code but the values are not getting populated in list box. please give your ideas.
I tried with list box which is having same values in all rows, it is working fine.
loop at itab.
select vbeln from ZSD_PS_BLAWB into ZSD_PS_BLAWB-vbeln
where BLAWBNO = itab-BLAWBNO and
BLAWBDT = itab-BLAWBDT and
CTRNO = itab-CTRNO.
if sy-subrc = 0.
index = 1.
list3-key = index.
list3-text = ZSD_PS_BLAWB-vbeln.
append list3 to list2.
index = index + 1.
endif.
endselect.
clear index.
CALL FUNCTION 'VRM_SET_VALUES'
EXPORTING
ID = 'ITAB-VBELN'
VALUES = list2
EXCEPTIONS
ID_ILLEGAL_NAME = 1
OTHERS = 2
IF SY-SUBRC 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
modify itab.
endloop.
Thanks in advance.Hi,
this is code example for listbox
TYPE-POOLS vrm .
DATA: lt_vrm_values TYPE TABLE OF vrm_value.
DATA: wa_vrm_values TYPE vrm_value.
PARAMETER p_list AS LISTBOX VISIBLE LENGTH 10.
INITIALIZATION.
wa_vrm_values-key = 'Key1'.
wa_vrm_values-text = 'Value1'.
APPEND wa_vrm_values TO lt_vrm_values.
wa_vrm_values-key = 'Key2'.
wa_vrm_values-text = 'Value2'.
APPEND wa_vrm_values TO lt_vrm_values.
wa_vrm_values-key = 'Key3'.
wa_vrm_values-text = 'Value3'.
APPEND wa_vrm_values TO lt_vrm_values.
AT SELECTION-SCREEN OUTPUT.
CALL FUNCTION 'VRM_SET_VALUES'
EXPORTING
id = 'P_LIST'
values = lt_vrm_values
EXCEPTIONS
id_illegal_name = 1
OTHERS = 2.
IF sy-subrc 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
To fill it with data from DB, just do select in INITIALIZATION and put that values with same alghoritmus.
Manas M.
P.S.: This is very easy question, you should use search ... -
Opening tiff image file and finding pixel values at each point
I want to open a tiff image file using java.Than i want to find out the pixel values at each point.Also if possible red,green and blue values.
please mail me answer or code if possible on mail id:
[email protected]Use Java Advanced Imaging to open the Tiff. There is
a tutorial on it. Look to the left for tutorials, look
for JAI, do what it says.
For getting the pixels, do this:
Use a PixelGrabber to get pixels in array:
int[] pixels = new int[w * h];
PixelGrabber pg = new PixelGrabber(img, x, y, w, h, pixels, 0, w);
pg.grabPixels();
Use a MouseMotionListner for
mouseMoved(MouseEvent moueEvent)
pixel = pixels[mouseEvent.getX() + (mouseEvent.getY()*width)]
int alpha = (pixel >> 24) & 0xff;
int red = (pixel >> 16) & 0xff;
int green = (pixel >> 8) & 0xff;
int blue = (pixel ) & 0xff;
Look up the API for MouseMotionListener, PixelGrabber, etc... -
How to find max value in single row
i would like to know that,
how can i display maximum value among several values in a single row of table
example : i have to get value 5
among 1 2 3 4 5 values of same row.Take a look at GREATEST function.
C.
Link to documentation added
Message was edited by:
cd -
Hi
My application is generating a 2-dimensional array of data as it performs multiple sweeps. I would like to take the mean of all the data in each row and thereby reduce to a 1-dimensional array. Does anybody have a quick solution.
(Sorry - I am posting many messages at present, I promise to share my acquired knowledge!!!).
Thanks
Ashley.Try this.
Attachments:
Mean.JPG 5 KB -
Styling report rows using the query result
Hello, is it possible to style a row in a report using the values returned by the underlying sql query?
For example, if my query returns a column called ROW_CLASS I would like to use the placeholder #ROW_CLASS# to style the row, e.g. specifying the row class.
Apparently such row attributes are not available to the apex developer. For each single column value I can set the "Tabular Form Attributes" and "Column Formatting", but I cannot set anything on the whole row.
In other words I can style the TDs but not the TRs.
I think this is clearly a "missing feature" that should be there, single the APEX engine that turns the query result into the HTML that displays the table can already access the column values via their placeholders. It would be sufficient to add some "row attributes" or "row class" field in the report.
It could be used for lots of useful things, in my particular case, highlighting rows that contain errors.
Also there is no way to perform that operation in CSS (e.g. get the TRs which contain at least one TD of class "ROWERROR"). I know it could be done in JS, but that's very messy for such a simple declarative problem.GChierico wrote:
Hello, is it possible to style a row in a report using the values returned by the underlying sql query? Yes, for standard reports, using custom report templates: +{thread:id=2493917}+
Interactive reports require the use of Dynamic Actions/jQuery.
Maybe you are looking for
-
Hi, Please let me know if there is any FM to convert USD to $ and also other country currency symbols. let me know if there are any standard tables in sap which are related to this. regards, Lakshmikanth.T.V
-
I just bought a new Canon 50D but can't open my raw files in Adobe CS4 Bridge or Photoshop.
The files show up as CR2 files and I get a message saying "could not complete your request because it is the wrong kind of document. I run on Windows XP. I would appreciate your help.
-
Can someone tell me how to change obj file in the applet
Thanks in advance. I have try to use the ObjLoad example in the java3d demo to change the obj file.But I fail to do this. I had use twe applet,one to change name,and then refresh the other frame to try to relod th obj file. but java.lang.NullPointerE
-
Changing Default Submitted Form Subject Line
After distributing a form, how do you change the default email subject line when the user submits it? For clarity, check the highlighted area in the screenshot below: I've created multiple forms for users, and would like to differentiate b/w them all
-
RFC to SOAP scenario (with out XI/PI)
Dear Experts , Is it possible to push data from RFC to Webservice with out using XI/PI. Regards, Kartheek.