Hi quick select statement question!
Hi Everyone,
I'm new to the board and somewhat new to sql too. So I have a small problem that I hope someone can help me with.
DATA
Name: time1 time2
Jack 1 2
Jack 2 3
Jack 3 4
Jack 8 9
Jane 3 4
I'd like to get a table that combines all the continuous times for each person so that it looks like this:
Jack 1 4
Jack 8 9
Jane 3 4
I'm desperate, and I appreciate it any help! Thanks!
sql>select * from t;
NAME T1 T2
Jack 1 2
Jack 2 3
Jack 3 4
Jack 8 9
Jane 8 9
sql>
select name,min(t1) t1,max(t2) t2
from(
select name,t1,t2,sum(flg) over(order by rownum) sm
from(
select name,t1,t2,
decode(lead(t1) over(partition by name order by t1),t2,0,
decode(lag(t2) over(partition by name order by t1),t1,0,1)) flg
from t))
group by name,sm;
NAME T1 T2
Jack 1 4
Jack 8 9
Jane 8 9
Similar Messages
-
Basic Quick Selection Tool Question
Is this just a newer way to do the same thing the other selections tools have been doing for years OR is there a benefit to this tool over the other selection tools?
The Quick Selection Tool does indeed operate differently from the Magic Wand Tool.
But it’s been introduced at least with CS3, so why the question now? -
Hi ABAP Gurus,
I have the following code.
DATA: BEGIN OF i_p0000 OCCURS 0,
pernr LIKE pa0000-pernr,
begda LIKE pa0000-begda,
endda LIKE pa0000-endda.
DATA: END OF i_p0000.
DATA: v_date_from TYPE d,
v_date_to TYPE d.
DATA: BEGIN OF PERNRZ_TAB occurs 0,
PERNR(8) TYPE N,
END OF PERNRZ_TAB.
RANGES: l_r_pernr FOR pa0000-pernr, "personnel number
SELECT PERNRZ1 FROM ZTESTHR1 INTO table PERNRZ_TAB
WHERE BEGDAZ1
BETWEEN v_date_from AND v_date_to.
OPEN CURSOR WITH HOLD s_cursor FOR
SELECT pernr
begda
endda
FROM pa0000
WHERE pernr IN l_r_pernr.
Fetch records into interface table.
FETCH NEXT CURSOR s_cursor
APPENDING CORRESPONDING FIELDS
OF TABLE i_p0000
PACKAGE SIZE s_s_if-maxsize.
IF sy-subrc <> 0.
CLOSE CURSOR s_cursor.
RAISE no_more_data.
ELSE.
SORT i_p0000 BY pernr.
I would like to retrieve records based on the values in PERNRZ_TAB. When I make the following change I am getting an error.
SELECT pernr
begda
endda
FROM pa0000
WHERE pernr IN PERNRZ_TAB.
Thanks in advance.
Regards,
bw_newbieSELECT pernr
begda
endda
<b>into table IT_PA0000</b>
FROM pa0000
<b>for all entries in PERNRZ_TAB
WHERE pernr = PERNRZ_TAB-PERNR.</b>
if you want to retrieve records from table for all the entries in any Internal table, you should use FOR ALL ENTRIES addition of SELECT statement.
this fetch may have more than 1 record, so you should give the INTO TABLE addition also.
define IT_PA000 internal table with pernr
begda
endda fields.
Check this.
Regards
srikanth
Message was edited by: Srikanth Kidambi -
Questions on select statement in the data model
Hi,
In the select statement, the order by statement seems only to work at the lowest level of the select statement. Is this true?
What is the the purpose of the group by statement in the select statement?
As far as I understand, the grouping is catered for in the data model.....
Regards,
KinFrom the oracle report docs:
The order of column values in a default group is
determined by the ORDER BY clause of the query for
SQL queries and by the sort column for Express queries.
For column values in user-created groups, however, you
must use Break Order to specify how to order the break
column's values.So order by in your sql query is affected by groups in your data model.
The purpose of a group by statement in your select statement is to group values for aggregation purposes, like
select department_id,
min(salary),
max (salary)
from employees
group
by department_id
order
by department_id;Grouping in the data model of a report is a little different than a group by clause, but not entirely. -
Issue with Select options in select statement - ABAP Question
Hi
I am facing an issue with select options. Select statement is returning sy-subrc as 4.
I wrote the program as below:
SELECT-OPTIONS:
s_kunnr FOR bsad-kunnr,
s_lifnr FOR bsak-lifnr,
s_gjahr FOR bsad-gjahr,
s_bukrs FOR bsad-bukrs,
s_saknr FOR bsad-saknr,
s_budat FOR bsak-budat.
In start of selection I have written the select statement as
SELECT * FROM bsak INTO TABLE lt_bsak
WHERE bukrs IN s_bukrs AND lifnr = s_lifnr AND gjahr IN s_gjahr AND budat IN s_budat AND saknr IN s_saknr.
In selection screen I have not entered any values and executed the program. I am not getting any result. When I debug that, sy-subrc is 4 at above select statement. But table has records.
If am removing the "lifnr = s_lifnr " condition in select then select is returning values.
I am not getting where I made the mistake. Please suggest.
Thank you
HanuHi,
The problem here with where condition select option lifnr = s_lifnr.
Use below select query.
SELECT * FROM bsak INTO TABLE lt_bsak
WHERE bukrs IN s_bukrs
AND lifnr IN s_lifnr
AND gjahr IN s_gjahr
AND budat IN s_budat
AND saknr IN s_saknr.
s_lifnr is a select option and you are passing it as parameter lifnr = s_lifnr.
if you want to pass this s_lifnr as single vale then pass in below mentioned way.
lifnr = s_lifnr-low
BR,
Vijay -
Quick help with a select statement...
Hello all,
I will try to lay this out as simply as possible. I have the following table in my code:
TYPES: BEGIN OF ty_table,
vbeln TYPE likp-vbeln,
lfdat TYPE likp-lfdat,
lfart TYPE likp-lfart,
wadat_ist TYPE likp-wadat_ist,
vstel TYPE likp-vstel,
route TYPE likp-route,
vsbed TYPE likp-vsbed,
inco1 TYPE likp-inco1,
inco2 TYPE likp-inco2,
kunnr TYPE likp-kunnr,
kunag TYPE likp-kunag,
brgew TYPE lips-brgew,
matnr TYPE lips-matnr,
arktx TYPE lips-arktx,
meins TYPE lips-meins,
lgmng TYPE lips-lgmng,
vgbel TYPE lips-vgbel,
name2 TYPE adrc-name2,
street TYPE adrc-street,
city1 TYPE adrc-city1,
region TYPE adrc-region,
post_code1 TYPE adrc-post_code1,
lifnr TYPE lfa1-lifnr,
name1 TYPE adrc-name1,
so_vbeln TYPE vbak-vbeln,
erdat TYPE vbak-erdat,
END OF ty_table.
DATA: it_table TYPE TABLE OF ty_table.
I then run through a select statement as follows:
* Get data from LIKP and LIPS.
SELECT a~vbeln a~lfdat a~lfart a~wadat_ist a~vstel a~route a~vsbed b~brgew a~inco1 a~inco2 a~kunnr a~kunag
b~matnr b~meins b~lgmng b~vgbel b~arktx INTO CORRESPONDING FIELDS OF TABLE it_table
FROM likp AS a
INNER JOIN lips AS b ON b~vbeln = a~vbeln
WHERE a~vstel IN so_vstel
AND a~wadat_ist IN so_wadat
AND b~mtart IN so_mtart.
That works fine. The next statement, in the report, is the following select. When this next select runs it clears all of the fields except for vbeln and erdat. I want c~vbeln to go into it_table-so_vbeln. Now it is going into it_table-vbeln.
* Get Sales order info from VBAK
SELECT c~vbeln c~erdat INTO CORRESPONDING FIELDS OF TABLE it_table
FROM lips AS a
INNER JOIN vbap AS b ON b~vbeln = a~vgbel
AND b~posnr = a~vgpos
INNER JOIN vbak AS c ON c~vbeln = b~vbeln
FOR ALL ENTRIES IN it_table
WHERE a~vgbel = it_table-vgbel.
I then tried to write the select statement by takign out "into corresponding fields" like the following but it gives my a syntax error on (it_table-so_vbeln , it_table-erdat).
* Get Sales order info from VBAK
SELECT c~vbeln c~erdat INTO (it_table-so_vbeln , it_table-erdat)
FROM lips AS a
INNER JOIN vbap AS b ON b~vbeln = a~vgbel
AND b~posnr = a~vgpos
INNER JOIN vbak AS c ON c~vbeln = b~vbeln
FOR ALL ENTRIES IN it_table
WHERE a~vgbel = it_table-vgbel.
Is there a way to write the second select (the select that is pulling data from VBAK) so that it will not clear the other entries in the table? Also, is there a way to combine the two selects into one join?
Regards,
DavisFollowing is the entire report, if that makes it easier:
*& Report Z_TRANS_EVAL
REPORT z_trans_eval.
TABLES: likp, lips, adrc, vbpa.
TYPE-POOLS: truxs.
TYPES: BEGIN OF ty_table,
vbeln TYPE likp-vbeln,
lfdat TYPE likp-lfdat,
lfart TYPE likp-lfart,
wadat_ist TYPE likp-wadat_ist,
vstel TYPE likp-vstel,
route TYPE likp-route,
vsbed TYPE likp-vsbed,
inco1 TYPE likp-inco1,
inco2 TYPE likp-inco2,
kunnr TYPE likp-kunnr,
kunag TYPE likp-kunag,
brgew TYPE lips-brgew,
matnr TYPE lips-matnr,
arktx TYPE lips-arktx,
meins TYPE lips-meins,
lgmng TYPE lips-lgmng,
vgbel TYPE lips-vgbel,
name2 TYPE adrc-name2,
street TYPE adrc-street,
city1 TYPE adrc-city1,
region TYPE adrc-region,
post_code1 TYPE adrc-post_code1,
lifnr TYPE lfa1-lifnr,
name1 TYPE adrc-name1,
so_vbeln TYPE vbak-vbeln,
erdat TYPE vbak-erdat,
END OF ty_table.
DATA: it_table TYPE TABLE OF ty_table,
wa_table LIKE LINE OF it_table,
it_table_csv TYPE truxs_t_text_data.
DATA : lv_tabix LIKE sy-tabix.
DATA temp_string TYPE string.
DATA w_adrnr TYPE vbpa-adrnr.
DATA: w_adrnr_sp TYPE vbpa-adrnr.
* Selction criteria
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-004.
SELECT-OPTIONS: so_vstel FOR likp-vstel,
so_wadat FOR likp-wadat_ist,
so_mtart FOR lips-mtart.
SELECTION-SCREEN END OF BLOCK b2.
* CSV output filename
SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE text-003.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT (16) text-002 FOR FIELD p_file.
PARAMETERS: p_file(30) TYPE c.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK b3.
START-OF-SELECTION.
* Get data from LIKP and LIPS.
SELECT a~vbeln a~lfdat a~lfart a~wadat_ist a~vstel a~route a~vsbed b~brgew a~inco1 a~inco2 a~kunnr a~kunag
b~matnr b~meins b~lgmng b~vgbel b~arktx INTO CORRESPONDING FIELDS OF TABLE it_table
FROM likp AS a
INNER JOIN lips AS b ON b~vbeln = a~vbeln
WHERE a~vstel IN so_vstel
AND a~wadat_ist IN so_wadat
AND b~mtart IN so_mtart.
* Get Sales order info from VBAK
SELECT c~vbeln c~erdat INTO CORRESPONDING FIELDS OF TABLE it_table
FROM lips AS a
INNER JOIN vbap AS b ON b~vbeln = a~vgbel
AND b~posnr = a~vgpos
INNER JOIN vbak AS c ON c~vbeln = b~vbeln
FOR ALL ENTRIES IN it_table
WHERE a~vgbel = it_table-vgbel.
* Get internal address number for ship to party
LOOP AT it_table INTO wa_table.
lv_tabix = sy-tabix. "update counter.
SELECT SINGLE adrnr FROM vbpa INTO w_adrnr WHERE
vbeln = wa_table-vgbel
AND parvw = 'WE'.
SELECT SINGLE lifnr FROM vbpa INTO wa_table-lifnr WHERE
vbeln = wa_table-vbeln
AND parvw = 'SP'
AND posnr = '000000'.
SELECT SINGLE name1 FROM lfa1 INTO wa_table-name1 WHERE
lifnr = wa_table-lifnr.
* Get address data from VBPA
SELECT city1 region post_code1 INTO CORRESPONDING FIELDS OF wa_table
FROM adrc WHERE
addrnumber = w_adrnr.
ENDSELECT.
* Update the internal table
MODIFY it_table INDEX lv_tabix FROM wa_table.
ENDLOOP.
END-OF-SELECTION.
* Call correct display procedure(s).
IF p_file <> ''.
* Save a CSV file
PERFORM display_csv.
ELSE.
*Display in ALV
PERFORM display_alv.
ENDIF.
*& Form display_alv
* text
* --> p1 text
* <-- p2 text
FORM display_alv .
DATA: gr_alv TYPE REF TO cl_salv_table,
gr_func TYPE REF TO cl_salv_functions,
gr_columns TYPE REF TO cl_salv_columns_table,
gr_column TYPE REF TO cl_salv_column_table,
gr_error TYPE REF TO cx_salv_error.
TRY.
CALL METHOD cl_salv_table=>factory
IMPORTING
r_salv_table = gr_alv
CHANGING
t_table = it_table.
CATCH cx_salv_msg INTO gr_error.
ENDTRY.
gr_func = gr_alv->get_functions( ).
gr_func->set_all( abap_true ).
gr_alv->display( ).
ENDFORM. " display_alv
*& Form display_csv
* text
* --> p1 text
* <-- p2 text
FORM display_csv .
DATA: w_filename TYPE string.
CONCATENATE p_file temp_string INTO w_filename.
CALL FUNCTION 'SAP_CONVERT_TO_CSV_FORMAT'
EXPORTING
i_field_seperator = ';'
TABLES
i_tab_sap_data = it_table
CHANGING
i_tab_converted_data = it_table_csv
EXCEPTIONS
conversion_failed = 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.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = w_filename
TABLES
data_tab = it_table_csv
EXCEPTIONS
OTHERS = 1.
PERFORM display_alv.
ENDFORM. " display_csv -
Problem with Select Statements
Hi All,
I have a performance problem for my report because of the following statements.
How can i modify the select statements for improving the performance of the report.
DATA : shkzg1h LIKE bsad-shkzg,
shkzg1s LIKE bsad-shkzg,
shkzg2h LIKE bsad-shkzg,
shkzg2s LIKE bsad-shkzg,
shkzg1hu LIKE bsad-shkzg,
shkzg1su LIKE bsad-shkzg,
shkzg2hu LIKE bsad-shkzg,
shkzg2su LIKE bsad-shkzg,
kopbal1s LIKE bsad-dmbtr,
kopbal2s LIKE bsad-dmbtr,
kopbal1h LIKE bsad-dmbtr,
kopbal2h LIKE bsad-dmbtr,
kopbal1su LIKE bsad-dmbtr,
kopbal2su LIKE bsad-dmbtr,
kopbal1hu LIKE bsad-dmbtr,
kopbal2hu LIKE bsad-dmbtr.
*These statements are in LOOP.
SELECT shkzg SUM( dmbtr )
INTO (shkzg1s , kopbal1s)
FROM bsid
WHERE bukrs = ibukrs
AND kunnr = ktab-kunnr
AND budat < idate-low
AND shkzg = 'S'
AND umskz EQ ''
GROUP BY shkzg.
ENDSELECT.
SELECT shkzg SUM( dmbtr )
INTO (shkzg1su , kopbal1su)
FROM bsid
WHERE bukrs = ibukrs
AND kunnr = ktab-kunnr
AND budat < idate-low
AND shkzg = 'S'
AND umskz IN zspgl
GROUP BY shkzg.
ENDSELECT.
SELECT shkzg SUM( dmbtr )
INTO (shkzg1h , kopbal1h)
FROM bsid
WHERE bukrs = ibukrs
AND kunnr = ktab-kunnr
AND budat < idate-low
AND shkzg = 'H'
AND umskz EQ ''
GROUP BY shkzg.
ENDSELECT.
SELECT shkzg SUM( dmbtr )
INTO (shkzg1hu , kopbal1hu)
FROM bsid
WHERE bukrs = ibukrs
AND kunnr = ktab-kunnr
AND budat < idate-low
AND shkzg = 'H'
AND umskz IN zspgl
GROUP BY shkzg.
ENDSELECT.
SELECT shkzg SUM( dmbtr )
INTO (shkzg2s , kopbal2s)
FROM bsad
WHERE bukrs = ibukrs
AND kunnr = ktab-kunnr
AND budat < idate-low
AND shkzg = 'S'
AND umskz EQ ''
GROUP BY shkzg.
ENDSELECT.
SELECT shkzg SUM( dmbtr )
INTO (shkzg2su , kopbal2su)
FROM bsad
WHERE bukrs = ibukrs
AND kunnr = ktab-kunnr
AND budat < idate-low
AND shkzg = 'S'
AND umskz IN zspgl
GROUP BY shkzg.
ENDSELECT.
SELECT shkzg SUM( dmbtr )
INTO (shkzg2h , kopbal2h)
FROM bsad
WHERE bukrs = ibukrs
AND kunnr = ktab-kunnr
AND budat < idate-low
AND shkzg = 'H'
AND umskz EQ ''
GROUP BY shkzg.
ENDSELECT.
SELECT shkzg SUM( dmbtr )
INTO (shkzg2hu , kopbal2hu)
FROM bsad
WHERE bukrs = ibukrs
AND kunnr = ktab-kunnr
AND budat < idate-low
AND shkzg = 'H'
AND umskz IN zspgl
GROUP BY shkzg.
ENDSELECT.>
Siegfried Boes wrote:
> Please stop writing answers if you understrand nothing about database SELECTS!
> All above recommendations are pure nonsense!
>
> As always with such questions, you must do an analysis before you ask! The coding itself is perfectly o.k., a SELECT with an aggregate and a GROUP BY can not be changed into a SELECT SINGLE or whatever.
>
> But your SELECTS mustr be supported by indexes!
>
> Please run SQL Trace, and tell us the results:
>
> I see 8 statements, what is the duration and the number of records coming back for each statement?
> Maybe only one statement is slow.
>
> See
> SQL trace:
> /people/siegfried.boes/blog/2007/09/05/the-sql-trace-st05-150-quick-and-easy
>
>
> Siegfried
Nice point there Siegfried. Instead of giving constructive suggestion, people here give a very bad suggestion on using SELECT SINGLE combined with SUM and GROUP BY.
I hope the person already look at your reply before he try using select single and wondering why he has error.
Anyway, the most important thing is how many loop expected for those select statements?
If you have like thousands of loop, you can expect a poor performance.
So, you should also look at how many times the select statement is called and not only performance for each select statement when you're doing SQL trace.
Regards,
Abraham -
Select statement on maintenance view.
Hello Friends,
I have a quick question. I have a maintenance view, and I want to do a select statement on this view in an ABAP program, but seems like the view is not filled with data when running the program.
How do I get the view to be populated at runtime in the ABAP program? the work area and the internal table is TYPE of the view..
Here's the code:
select * into wa
from view
where bukrs = P_BUKRS
vtweg in S_CHNL.
append wa to it.
endselect.
best regards BHello B,
Just to inform you: "You can select data only from Database Views".
You can design a work-around for this, by taking look @ the Join tables. May i know form which View you want to get the data?
BR,
Suhas -
Selected state issue with Menu Module V2
OK so I am getting an issue with Menu Module V2. I have used this before with success but this time I have hit a wall. I possed this question to BC live chat and they bugged out real quick.
The site in construction is http://www.urbanista.com.au
What is happening is that in the top right tools nav with the headings Home, Services, People, Contact Us using Menu Module V2. The Heading Services has a drop down and this is where the issue resides. Roll over any of these nav devices and you will see they will highlight orange. Home is already auto activating its Selcted state. Click on Contact Us and it will do the same. Roll over and click on Services and it appears to have worked. While in Services roll over the drop down again and you will see all links have activated the Selected state. This is the issue. If you view the code of the Services UL you will see only the Services state has been alocated the Slected state. See below:
<li id="Services" class="selected">
<a href="/services.htm">Services</a>
<ul>
<li id="tools-panningdev">
<li id="tools-housing">
<li id="tools-urban-renewal">
<li id="tools-project-management">
<li id="tools-feasibility-tools">
<li id="tools-governance-systems">
<li id="tools-communications">
<li id="tools-projects">
</ul>
</li>
The CSS that runs the nav is as follows:
ul.dropdown {
font-weight: normal;
font-family: Arial, Helvetica, sans-serif;
font-style: normal;
text-decoration: none;
ul.dropdown li {
background-color: transparent;
color: #999;
padding-top: 5px;
padding-right: 10px;
padding-bottom: 5px;
padding-left: 10px;
font-size: 12px;
ul.dropdown li.hover,
ul.dropdown li:hover {
background-color: transparent;
color: #FFF;
ul.dropdown a:link,
ul.dropdown a:visited {
color: #FFF;
text-decoration: none;
ul.dropdown a:hover { color: #ff871f; }
ul.dropdown a:active {
color: #b33b00;
/* -- level mark -- */
ul.dropdown ul {
width: 150px;
margin-top: 1px;
background-image: url(/images/nav-transparency.png);
background-repeat: repeat;
color: #FFF;
ul.dropdown ul li {
font-weight: normal;
ul.dropdown li.selected a {
color: #ff871f;
The last entry 'ul.dropdown li.selected a {color: #ff871f;}' is required in order to allocate a Slected State. Without it not Selected state is active and the links al remian white.
I have tried all manner of combinations and additonal tags with no success. Any suggestions greatly appreciated. I have not modified the default Javascript provided by BC in the system apart from allocating the required ulTagClass as specified. The Javascript in the supplied 'container.html' is as follows:
<script type="text/javascript" >
// ids need to be unique per page, use different ones if you are including multiple menus in the same page
// id of the nav tag, used above
var divTagId = "myMenu1";
// desired id for 1st <ul> tag
var ulTagId = "myMenu1List";
// desired class for 1st <ul> tag
var ulTagClass = "dropdown dropdown-vertical";
if ((null !== ulTagId) && ("" !== ulTagId)) {
document.getElementById(divTagId).getElementsByTagName("ul")[0].setAttribute("id",ulTagId );
if ((null !== ulTagClass) && ("" !== ulTagClass)) {
document.getElementById(divTagId).getElementsByTagName("ul")[0].className = ulTagClass;
// this will set the selected state
if ((null !== ulTagId) && ("" !== ulTagId)) {
catSetSelectedCSSItem(ulTagId);
</script>
Lastly this is one of the recomended navs by BC at the following address: http://lwis.net/free-css-drop-down-menu/
I have used these before with success but for the life of me this has stumped me big time.Hi Matthew,
Having a super quick look at the code I'd say it's because of:
ul.dropdown li.selected a {
color: #ff871f;
This affects all the child elements.
To override this down the line you could do something like:
ul.dropdown li.selected ul li a {
color: #fff;
This would override the parent link color when selected.
You could probably then also add:
ul.dropdown li.selected ul li.selected a {
color: #ff871f;
For the dropdown selected states.
That's a quick look though so don't quote me too much -
Hint in Update or Select Statement in an inline query ??
Hi ,
I had an update statement that will get the data from the inline select statement,now where can i can keep the hint ,either in update statement or in Select statement...
Please let me know if my sample script is wrong or any better way to approach...Please assume that Salary table had millions of employee's salary records.
update emp
set salary = salary + (select /*+ full(a) parallel(a,4) */ salary from Salary
where experience > 5 and empno = 55 )
where empno = 85Thanks
RedeYou would put the hint in the select statement as you have it, but it won't work until you alias your table name to "a" since that is how you are referencing it in the hint:
update emp
set salary = salary + (select /*+ full(a) parallel(a,4) */ salary from Salary a
where experience > 5 and empno = 55 )
where empno = 85
NOTE I added the "a" right after the Salary table name AND you can only do parallel updates on partitioned table, but the select will run in parallel to at least get the data for you quickly.
To answer your other question about syntax, it is incorrect and there are a lot of ways to write it but a straight forward way would be to use the merge statement
merge into emp e
using (select /*+ full(s) parallel(s,4) */ s.salary from salary s where s.experience > 5) s
on (e.empno = s.empno)
when matched then update
set salary = s.salary; -
Performance problem of asset selection statement.
Hi guys quick question.
SELECT a~bukrs
a~anln1
b~anln2
a~anlkl
a~aktiv
a~txt50
a~lvtnr
b~afabe
b~afabg
b~ndjar
b~ndper
INTO TABLE it_anla
FROM anla AS a
INNER JOIN anlb AS b
ON a~bukrs EQ b~bukrs
AND a~anln1 EQ b~anln1
WHERE a~bukrs IN s_bukrs
AND a~anln1 IN s_anln1
AND a~anln2 EQ '0000'
AND a~anlkl IN s_anlkl
AND a~aktiv EQ '00000000'
AND a~lvtnr IN s_lvtnr
AND b~afabe EQ 01.
I have a select statement which is filtered by capitalization date which is the field AKTIV. This select alone has 450 thousand hits. Having an ANLN2 = 0 and AKTIV = blank/no date means that the asset group is no longer active.
Now for another scenario I have to retrieve table ANLA again excluding all the Main Asset Number/ANLN1 found on that table.
Is there a way to select by doing it only once?
I tried to pass all the anln1 to a range table but the program dumps. I think the range table can't handle too many entries.
Retrieving all the entries from the DB then processing it takes longer.
I tried to delete the table using a loop but it takes to long as it process the table every loop.
LOOP AT it_anla WHERE anln2 EQ '0000' AND aktiv EQ '0000000'.
DELETE it_anla WHERE bukrs EQ it_anla-bukrs AND anln1 EQ it_anla-anln1.
ENDLOOP.
Thanks.
Edited by: Thomas Zloch on Sep 21, 2010 5:39 PM - please use code tagsModerator message - Welcome to SCN
If the range table for anln1 is large and contains distinct values, you can try using it in a FOR ALL ENTRIES construct rather than IN.
Rob -
Howto create 'select statement' that returns first row? (simple table)
quick question that drives me crazy:
Say I have the following table:
ID....car_model....point_A....total
1........333.............NY..........54
2........333.............NJ..........42
3........333.............NH...........63
4........555.............NJ...........34
5........555.............PA...........55
I would like to create a select statement that return car_model which the starting point is NJ - in this example it's only 555.
thanks for any tipsfair enough.
the problem is this: given the table below, I need to create a report that reflects car rentals from specific location. you can rent a car from different locations; a car has a starting point (like a flight itinerary) so consider this:
Mark rent a car with the following itinerary:
NY--> NJ
NJ--> PA
PA-->FL
FL-->LA
the end user would like to see all car that were rented between X and Y and start point was NJ, so in the example above, the starting point is NY so it doesn't match the end users' criteria.
The table is organized in the following manner: ID....car_model....point_A....total
* I don't know whey the someone choose point_A as a column description as it just suppose to be 'location'
so, back to my first example:
ID....car_model....point_A....total
1........333.............NY..........54
2........333.............NJ..........42
3........333.............NH...........63
4........555.............NJ...........34
5........555.............PA...........55
if I do this:
Select car_model from myTable where point_A='NJ'
the return result will be 333 and 555 but that is in correct because 333 starting point is NY.
I hope I provided enough information, thanks -
How to find the number of fetched lines from select statement
Hi Experts,
Can you tell me how to find the number of fetched lines from select statements..
and one more thing is can you tell me how to check the written select statement or written statement is correct or not????
Thanks in advance
santoshHi,
Look for the system field SY_TABIX. That will contain the number of records which have been put into an internal table through a select statement.
For ex:
data: itab type mara occurs 0 with header line.
Select * from mara into table itab.
Write: Sy-tabix.
This will give you the number of entries that has been selected.
I am not sure what you mean by the second question. If you can let me know what you need then we might have a solution.
Hope this helps,
Sudhi
Message was edited by:
Sudhindra Chandrashekar -
Secondary Index Select Statement Problem
Hi friends.
I have a issue with a select statement using secondary index,
SELECT SINGLE * FROM VEKP WHERE VEGR4 EQ STAGE_DOCK
AND VEGR5 NE SPACE
AND WERKS EQ PLANT
%_HINTS ORACLE
'INDEX("&TABLE&" "VEKP~Z3" "VEKP^Z3" "VEKP_____Z3")'.
given above statement is taking long time for processing.
when i check for the same secondary index in vekp table i couldn't see any DB index name with vekp~z3 or vekp^z3 or vekp____z3.
And the sy-subrc value after select statement is 4. (even though values avaliable in VEKP with given where condition values)
My question is why my select statement is taking long time and sy-subrc is 4?
what happens if a secnodary index given in select statement, which is not avaliable in that DB Table?Hi,
> ONe more question: is it possible to give more than one index name in select statement.
yes you can:
read the documentation:
http://download.oracle.com/docs/cd/A97630_01/server.920/a96533/hintsref.htm#5156
index_hint:
This hint can optionally specify one or more indexes:
- If this hint specifies a single available index, then the optimizer performs
a scan on this index. The optimizer does not consider a full table scan or
a scan on another index on the table.
- If this hint specifies a list of available indexes, then the optimizer
considers the cost of a scan on each index in the list and then performs
the index scan with the lowest cost. The optimizer can also choose to
scan multiple indexes from this list and merge the results, if such an
access path has the lowest cost. The optimizer does not consider a full
table scan or a scan on an index not listed in the hint.
- If this hint specifies no indexes, then the optimizer considers the
cost of a scan on each available index on the table and then performs
the index scan with the lowest cost. The optimizer can also choose to
scan multiple indexes and merge the results, if such an access path
has the lowest cost. The optimizer does not consider a full table scan.
Kind regards,
Hermann -
Can we use is null in our select statement in ABAP program
hi,
I want to use 'is nul' or 'not null' in select statement of my ABAP program for any field. I have written below query but I am getting sy-subrc = 4 and getting no data. Can anyone resolve this.Hi,
I think you've posted your question on the wrong forum. This is the SAP Business One development forum which is not part of ERP and doesn't include any ABAP or Netweaver programming.
For a list of forums please see here:
http://forums.sdn.sap.com/index.jspa
Kind Regards,
Owen
Maybe you are looking for
-
My MSI KT6 Delta system no longer boots any further than the memory test? why? any ideas? any solutions other than replacing the motherboard etc. some background: motherboard: MSI KT6 Delta CPU: AMD Athlon XP 2800 Memory: 1Gb branded Graphics: Geforc
-
ITunes 6.0.2 clips music at end
iTunes 6.0.2 is clipping music at the end of MP3 files by 1-2 seconds. This has not happened before but is consistent on both a G4 iMac and an Intel iMac and for different songs. Playing the same file in the finder's preview does not cut off. The Cro
-
We are getting the below error while undeploy and deploy the Watched folder Application, Reason of failure is-----Failure to invoke the job Watched folder Failure to invoke the job Watched folder Service :Watched folder is not in a RUNNING STATE ALC
-
IPhone 5 wifi issue. IOS 6.0.2 vs IOS 6.0.1
Hi all, Just want to ask if IOS 6.0.2 is better than IOS 6.0.1? Recently, i noticed that my iphone 5 will disconnect the wifi connection after a while when not in use (standby / sleep mode_10 mins). When first bought, the phone was perfect. Sometimes
-
ECC 6.0 Script Error - Text elements
Dear All, I'm facing an error in the script saying that: Error log F0 251 In form XXX / window MAIN , the element 510-C (Text-C) is missing F0 251 In form XXX / window MAIN , the element 515 (Heading) is missing F0 251 In form XXX/ window MAIN , the