How to get the account numbers which maintains negative balance for consecutive 5 days
Here is what I am trying to do
I am trying to get the accounts which has negative balance consecutively for five days
Here in this a/c 1 and 5 has consecutive negative balance
how to pull these accounts using sql query.
create table #p(cal date, ac# int, bal int)
insert into #p values ( GETDATE(), 1, -1),
( GETDATE(), 2, 1),
( GETDATE(), 3, 1),
( GETDATE(), 4, -2),
( GETDATE(), 5, -6),
( GETDATE()-1, 1, -1),
( GETDATE()-1, 2, 1),
( GETDATE()-1, 3, 1),
( GETDATE()-1, 4, 2),
( GETDATE()-1, 5, -7),
( GETDATE()-2, 1, -2),
( GETDATE()-2, 2, -1),
( GETDATE()-2, 3, -1),
( GETDATE()-2, 4, 2),
( GETDATE()-2, 5, -6),
( GETDATE()-3, 1, -2),
( GETDATE()-3, 2, -1),
( GETDATE()-3, 3, -1),
( GETDATE()-3, 4, 2),
( GETDATE()-3, 5, -2),
( GETDATE()-4, 1, -4),
( GETDATE()-4, 2, 1),
( GETDATE()-4, 3, 1),
( GETDATE()-4, 4, -2),
( GETDATE()-4, 5, -2),
( GETDATE()-5, 1, -4),
( GETDATE()-5, 2, 1),
( GETDATE()-5, 3, 1),
( GETDATE()-5, 4, 2),
( GETDATE()-5, 5, -1)
-- drop table #p
@ Jing
Again not sure if it is ok to comment on other people's answers, I hope you don't take it the wrong way, but your query will not account for CONSECUTIVE days. E.g. if the acc balance goes back to a positive value, day count must be reset.
Now I understand why people answered this so much faster than me LOL.
Edit: Besides, the requeriment for the acc being returned is that its value was negative for 5 days (120 hours). When a given account balance first switches to a negative value, it has 0 hours in that state. It all add a day to its "negative balance consecutive
day count" property the next time its value is checked (cal + 1). With that said, if your query worked, it would be cnt > 6 not cnt > 5.
Thanks for pointing the issue. I have improved my query to address it.
I try to come up with something to my understanding to the questions. It may not interpret right from the question itself for various reasons. I still consider it is a great learning experience. Thank you for your comments.
create table #p(cal date, ac# int, bal int)
insert into #p values ( GETDATE(), 1, -1),
( GETDATE(), 2, 1),
( GETDATE(), 3, 1),
( GETDATE(), 4, -2),
( GETDATE(), 5, -6),
( GETDATE()-1, 1, -1),
( GETDATE()-1, 2, 1),
( GETDATE()-1, 3, 1),
( GETDATE()-1, 4, 2),
( GETDATE()-1, 5, -7),
( GETDATE()-2, 1, -2),
( GETDATE()-2, 2, -1),
( GETDATE()-2, 3, -1),
( GETDATE()-2, 4, 2),
( GETDATE()-2, 5, -6),
( GETDATE()-3, 1, -2),
( GETDATE()-3, 2, -1),
( GETDATE()-3, 3, -1),
( GETDATE()-3, 4, 2),
( GETDATE()-3, 5, -2),
( GETDATE()-4, 1, -4),
( GETDATE()-4, 2, 1),
( GETDATE()-4, 3, 1),
( GETDATE()-4, 4, -2),
( GETDATE()-4, 5, -2),
( GETDATE()-5, 1, -4),
( GETDATE()-5, 2, 1),
( GETDATE()-5, 3, 1),
( GETDATE()-5, 4, 2),
( GETDATE()-5, 5, -1),
( GETDATE()-6, 5, -1)
--update #p
-- set bal=-1*bal
-- where cal='2014-09-22' and [ac#]=5
;with mycte as ( Select *
,row_number() Over(Order by [ac#], cal) - row_number() Over(Partition by [ac#], sign(bal) Order by [ac#], cal) rnDelta
from #p)
,mycte1 as (
select * ,
sum(Case when bal< 0 Then 1 Else 0 End) Over(Partition by [ac#], rnDelta Order by [ac#],cal ) cnt
from mycte
SELECT distinct [ac#] from mycte1
Where cnt>=5
drop table #p
Similar Messages
-
How to get the serial Numbers issued for an STO
Hi,
I created my own STO and mapped a serialised material for the same using transaction. I increased the stock by issuing serial numbers. The /SYCLO/MM_DOPURCHASEORDER_GET BAPI returns the PO header, item and longtext details. I want the serial numbers which are issued to the STO and the list of serial numbers for which the receipts has been done.
I want to know how to get the serial numbers which are issued to the STO throught the standard function module. I want only the issued serial numbers not the one for which the receipts has been done.
I tried using the standard BAPI, "BAPI_PO_GETDETAIL1" to get the serial number collection. But the FM is not returning the issued serial number as well as the list of serial numbers for which the receipts has been done. It is returning only the PO history in which the list of document number are present.
Thanks in Advance,
Mohan.Hi,
Using the transaction "MB1C" and movement type "561", I filled the required details such as Material Number, Quantity, Storage Location and Batch. After filling all these details, when I press enter, it will ask for me to enter the serial numbers equal to the quantity specified. I entered the serial numbers by selecting the available serial numbers for that particular material by pressing F4 help.
Please let me know if you need any more inputs in this regards.
Thanks,
Mohan. -
How to get the form name which is used in standard tcode like me23n in sap
how to get the form name which is used in standard tcode like me23n in sap
Moderator message: four out of four threads locked, please read and understand the following before posting further:
[Rules of engagement|http://wiki.sdn.sap.com/wiki/display/HOME/RulesofEngagement]
[Asking Good Questions in the Forums to get Good Answers|Asking Good Questions in the SCN Discussion Spaces will help you get Good Answers]
Edited by: Thomas Zloch on Nov 18, 2011 1:32 PMhow to get the form name which is used in standard tcode like me23n in sap
Moderator message: four out of four threads locked, please read and understand the following before posting further:
[Rules of engagement|http://wiki.sdn.sap.com/wiki/display/HOME/RulesofEngagement]
[Asking Good Questions in the Forums to get Good Answers|Asking Good Questions in the SCN Discussion Spaces will help you get Good Answers]
Edited by: Thomas Zloch on Nov 18, 2011 1:32 PM -
How to get the Checked box which are clicked
for(int k=0;.....
jsp code
<input type=checkbox name=checkbox value='<%=k%>' >
how to get the particular Checkbox which are checked???String[] checkedValues = request.getParameterValues("checkbox");You'll get an array filled with the values only for the checked boxes. In other words, if no boxes are checked, checkedValues will be null or checkedValues.length == 0, not sure, going from memory.
Hope this helps!
Patrick -
How to get the list of users who has access for list of tcodes.
How to get the list of users who has access for list of tcodes.
Go to transaction SUIM, this has a number of reports for users/authorisations
open the Where used>Autorization Values>In Users
and double click to execute
in authorisation object, enter S_TCODE
then press the "Enter Values" button
It will offer entry boxes to put the transaction code you are interesed in.
Then execute and the list of users with access to this transaciton code will be returned. -
How to get the last wbs which is displayed in transaction code cj03?
Dear Experts,
I want to get the last wbs which are displayed in transaction code cj03, i have written below program,but i found it is incorrect. because the sort of wbs in cj03 is not equal to table prps. the last wbs in cj03 is not equal to table prps.
who can tell me how to get last wbs which is displayed in cj03?
SELECT
PRPS~STUFE
PRPS~POSID
PROJ~POST1
INTO CORRESPONDING FIELDS OF TABLE WA_PRPS_TEMP FROM PRPS INNER JOIN PROJ ON PROJPSPNR = PRPSPSPHI
WHERE PROJ~PSPID EQ P_PROJECT.
WA_TLINE = LINES( WA_PRPS_TEMP ).
READ TABLE WA_PRPS_TEMP INDEX WA_TLINE.
IF WA_PRPS_TEMP-POSID = P_lastWBS.
P_LAST = 1
endif.
Best Regards,
MerryHi Merry ,
The WBS elements are stored in the table PRPS , so please try using the conversion exit and use the data in internal format then use it in the IF condition.
Check the FM CONVERSION_EXIT_ABPSN_INPUT and CONVERSION_EXIT_ABPSN_OUTPUT
Regards,
Arun -
How to get the PDF data which i have send to Spool
Dear Freinds,
My requirement is to display the output which iam getting from a custom report(ZSALARY) in the form of PDF . So now i wanted to display the ALV output on to my desktop (as of now) in PDF format.
i have done the below coding please correct me why iam not getting the same data which is coming out of my report in the PDF, iam passing the same internal table.
IF NOT it_final[] IS INITIAL. -
>IT_FINAL is my main internal table in the report ZSALARY
DATA : count TYPE syprcop,
days TYPE sypexpi,
params TYPE pri_params,
valid TYPE c,
pdf_table TYPE rcl_bag_tline,
spoolid TYPE rspoid,
pdf_fsize TYPE i.
CALL FUNCTION 'GET_PRINT_PARAMETERS'
EXPORTING
destination = 'LP01'
copies = count
list_name = 'ZSALARY' -
tHIS IS MY REPORT NAME
list_text = 'ZSSPOOL'
immediately = ' '
release = 'X'
new_list_id = 'X'
expiration = days
line_size = 90
line_count = 65
layout = 'X_PAPER'
sap_cover_page = 'X'
receiver = 'SAP*'
department = 'System'
no_dialog = 'X'
IMPORTING
out_parameters = params
valid = valid.
NEW-PAGE PRINT ON PARAMETERS params NO DIALOG.
WRITE : 'hi this is the test for spool'.
NEW-PAGE PRINT OFF.
COMMIT WORK.
WRITE : / 'The Spool no is ', sy-spono. "system variable for spool no
spoolid = sy-spono . -
At this point i can see the spool no.
CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
EXPORTING
src_spoolid = spoolid
no_dialog = 'X'
IMPORTING
pdf_bytecount = pdf_fsize
TABLES
pdf = pdf_table
EXCEPTIONS
OTHERS = 0.
CHECK sy-subrc = 0.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
bin_filesize = pdf_fsize
filename = 'C:\Documents and Settings\Administrator\Desktop\test.pdf'
filetype = 'BIN'
TABLES
data_tab = it_final
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
OTHERS = 5.
ENDIF.
if i go and on my desktop it is saying the below error "ADOBE READER COUDNT OPEN 'test.pdf'
because it is either not supported file type or because the file has been damaged.
my aim is to get the data which is there in IT_final in the PDF .....please correct me the parameters which i have given wrong. my doubt is in GUI_download fM in the tables should i pass it_final or
the pdf_table coming from'CONVERT_ABAPSPOOLJOB_2_PDF'...... i tried this option iam able to open and it is just giving message which i kept before this FM i.e WRITE : 'hi this is the test for spool'.
what i should to get my internal table data.
Pls help.
regards
srinivas.Dear Karthik,
Thank you for giving me the link there by iam able to get the ouput download int he pdf
as below code , but now a small problem for me .......i have 10 fileds in the Report ouput ....but however in the pdf output i can see only 8 fields and the two fields got truncated . Could you please tell me what
i have to change in my below code so that i can get all the values
IF NOT it_final[] IS INITIAL.
data : it_tsp01 type standard table of tsp01,
l_wa_tsp01 type tsp01.
CALL FUNCTION 'GET_PRINT_PARAMETERS'
EXPORTING
destination = 'LP01'
copies = count
list_name = 'ZHR_BON'
list_text = 'ZSSPOOL'
immediately = ' '
release = 'X'
new_list_id = 'X'
expiration = days
line_size = 90
line_count = 65
layout = 'X_PAPER'
sap_cover_page = 'X'
receiver = 'SAP*'
department = 'System'
no_dialog = 'X'
IMPORTING
out_parameters = params
valid = valid.
SUBMIT (sy-repid) TO SAP-SPOOL
SPOOL PARAMETERS mstr_print_parms
WITHOUT SPOOL DYNPRO
WITH pnppernr = p0001-pernr
AND RETURN.
CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
EXPORTING
src_spoolid = spoolid
no_dialog = 'X'
DST_DEVICE = params-PDEST
IMPORTING
pdf_bytecount = pdf_fsize
TABLES
pdf = pdf_table
EXCEPTIONS
OTHERS = 0.
CHECK sy-subrc = 0.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
bin_filesize = pdf_fsize
filename = 'C:\Documents and Settings\Administrator\Desktop\test.pdf'
filetype = 'BIN'
TABLES
data_tab = pdf_table "it_final
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
OTHERS = 5.
ENDIF.
Please tell me how i can get the all the fields which are there in my normal alv output ......
Case 1) .i wanted all the 10 fields in PDF to be displayed without truncated , I have checked in Spool ........ i found all the fields are there .....but however when i check the downloaed PDF i can see some fields are getting truncated.
Case 2) However if on the ALV output if the user hides 2 fields out of 10 fields then only 8 feilds which are appearing on the output before sending the Spool should only be displayed in PDF as well -
> for this scenario what i have to do.
Thanks Once again.
regars
srini. -
How to get the page numbers of a word/mpp/execl doc using Java?
Hi,
I meet a problem in Java programming. I want to get the page numbers of a Word/MPP/EXECL/PDF document. For exmaple, if a PDF docment have 10 pages, I need get the 10 . How to get it using Java?
Please advise me as soon as possible if you have any good suggestions! Thanks!
YinThere are several good tools that allow you to access COM objects from Java. Here are two of the better ones:
Bridge2Java
http://www.alphaworks.ibm.com/tech/bridge2java
J-Integra
http://www.linar.com/
Both of these tools will allow you to access MS Office products (including Word and Excel) via COM interfaces. -
I scratched my iTunes card and some of the numbers have come off. How do I get the missing numbers?
See this support article:
http://support.apple.com/kb/TS1292
If you can't get to work after perusing that page, contact the iTunes Store Support; instructions are at the bottom of that article.
Regards.
Forum Tip: Since you're new here, you've probably not discovered the Search feature available on every Communities page, but next time, it might save you time (and everyone else from having to answer the same question multiple times) if you search a couple of ways for a topic, both in the relevant forums and in the Apple Knowledge Base, before you post a question. -
SAP Cloud for customer how to get the Account ID and UUID from cloud
Hi Experts,
I have small requirement in cloud for customer.
How to get all the account id with UUID in excel sheet using any SDK or other ways?
Any way to get this information because i have tried using "Mass Data Maintenance" but not getting any information.
anyone know how can i get this information in cloud system?
Many thanks,
MithunHi Mithun,
In my understanding there SAP will not share IP address of tenant. If this is really urgent you should discuss to SAP Partner coach or any other representative. SAP network team will not directly communicate with you, this will require numerous approval inside SAP itself.
Thanks
Sunil Maurya -
How to get the date on which a material has gone into stock
Dear All,
Suppose that I have some 20 unrestricted stock for a material. I want to know on which date the same has gone into stock ..Maybe 15 might have gone before 2 weeks and 5 might have gone a couple of days ago.
How can we get the details for the same .
Thanking you in advance,
ShankarAlthough you can look at the materia documents created for this material in recent past but that is not a way to track this kind of information. Batch management can be used for enabling tracking of this kind of information. Take for example following situation -
1st January 100 PC IN
10th January 50 PC IN
1st Feburary 75 PC OUT
2nd Feburary 25 PC OUT
You get only this kind of information from material documents but with this information it is not possible to know what you are looking for. If this is the requirement then Batch Management should be enabled.
Cheers,
Sanjeev -
How to get the group key, which an approval task assign to
Hi,
When a user is assign to OIM Group (i.e. from User Detail >> Group Membership form), I will call an approval process (using Access Policy).
In that approval process, I have defined two tasks.
1) Assign Approval to Group -> NOT conditional
2) Remove OIM Group From User -> conditional
So, from the 1) task, I will assign this approval to a OIM Group.
If the user click "Approva", a provisioning process will be fired.
If the user click "Deny" (Reject), 2) task will be run.
What I want is this.
From this 2) task, I need to get the "OIM Approval group" key or name (which this approval is assigned to)......
Note: I need to get this group info in the "Approval Process Task" -> "Integration" -> "Map"
Regards,
ChaturangaHi,
Yes. I have done that.
Now what I want is this. If the approver "Deny" (Reject) the approval task, I will call another task in the approval process. From that task, I need to run a code, which remove the user from OIM Group.
So, to do it, I have written a java code and created a adapter. So, as a input parameter for that code, I need to give the approval group name(i.e. the OIM group, above approval task is assign to).
How can I get the OIM approval group, which the person who Deny the approval belongs to, from this new approval process task???
Regards,
Chaturanga -
How to get the total numbers of pages have been printed using pl/sql
Dear All ,
I want to store the total number of physical pages printed into a database table,, how could I retrieve the value of the total number of pages .
I am using Oracle Report 6i
thnxxx in advance :)At the end of your report (i.e. after all the frames from your data model) place a dummy field. You can get the page number with srw.get_page_num in the format trigger of this field. Since this is the last field of your report, this is also the last page number.
-
How to get the error message which causes Synonym Invalid?
Hi,
I created a synonym in USER_B for a table in USER_A.
I have given all priveleges to USER_B from USER_A.
I created a package. In that I am using this synonym. Its working fine.
Today I have seen that.. the synonym is showing as invalid.
Even I recompiled the synonym. But its still showing as Invalid in PL/SQL developer.
Here I would like to see the error message which cause the synonym invalid.
How can I see the error message.?
Thank you,
Regards,
Gowtham Sen.Makes perfect sense. Oracle automatically attempts to revalidate objects when you try to use them.
SQL> create table t (
2 col1 NUMBER);
SQL> create or replace procedure p is
2 x POSITIVE;
3 begin
4 SELECT COUNT(*)
5 INTO x
6 FROM t;
7 end p;
8 /
Procedure created.
SQL> drop table t purge;
Table dropped.
SQL> select status
2 from user_objects
3 where object_name = 'P';
STATUS
INVALID
SQL> create table t (
2 col1 NUMBER);
Table created.
SQL> select status
2 from user_objects
3 where object_name = 'P';
STATUS
INVALID
SQL> exec p
BEGIN p; END;
ERROR at line 1:
ORA-06502: PL/SQL: numeric or value error
ORA-06512: at "UWCLASS.P", line 4
ORA-06512: at line 1
SQL> select status
2 from user_objects
3 where object_name = 'P';
STATUS
VALID
SQL> Even when the procedure has a problem ... the revalidation takes place. -
How to get the button name which triggred the post back
i have multiple buttons on the apex page most of those have the event type as "post back". is there any way to get the button name through pl/sql which raised the post back event ?
Tried v('REQUEST') or :REQUEST?
Maybe you are looking for
-
I have two separate itune accounts under two different email accounts and would like to combine them under one account. Is this possible and if so, how do I do it?
-
Can we use receiver enhancement feature for a web service scenario?
Hi Experts, We have to send across an invoice to web service enabled legacy system from ECC. ECC>ABAP Proxy>SAP PI>SOAP Adapter>Legacy System1 ECC>ABAP Proxy>SAP PI>SOAP Adapter>Legacy System2 Requirement is like if the invoice number starts with 1A,
-
What cable do I need to connect Satellite C660-1K9 to TV device?
Hey guys! I basically just need to know what kind of cable I would need to plug my laptop up to my television. I have a Toshiba Satellite C660-1k9 laptop and my tv is make by Samsun. Thanks!
-
Newbie: Edit Drupal site in Dreamweaver?
Hi, I've got a trial version of Dreamweaver and I'm attempting to use it with a Drupal site but not having any luck so far. I've downloaded and installed the Drupal extension for Dreamweaver, Dreamweaver will connect to the site via FTP and download
-
Prevent requisitioner field (EBAN-AFNAM) from PR to be copied to PO in ME59
Hi, Is it possible, throught customizing, to prevent the content of requisitioner field (EBAN-AFNAM) of PR to be copied to PO when converting the PR to PO via ME59? Thanks for your help in advance.