SQL Statement needed for Query Generator
Dear Experts,
My view has the following three columns.
1, Start Date
2. End Date
3. Balance.
I need an SQL statement to write in query generator, which has to check if EndDate is less than the Current date and balance is above zero. If so, it assumes the last date of the job is already over, outstanding materials not yet been returned. Hence it has to return 'Pending'. If EndDate is greater than current date, it means final date for completion of the process is yet to come. So the task is in progress, hence it has to return 'Progress'. If the balance is Zero, all materials connected with the task have been received either as a FG or as Raw Materials. So it has to return, 'Completed'. I need a singe SQL Statement for this.
Please help me.
Thanks in advance.
Regards
Anand
Dear Anand,
Try this one:
CASE balance WHEN 0 THEN 'Completed' ELSE CASE WHEN DATEDIFF(DD, EndDate, GetDate()) >= 0 THEN 'Progress' ELSE 'Pending' END END
I have assumed you don't have negative balance. It that is not true, give me the complete case.
Thanks,
Gordon
Thanks,
Gordon
Similar Messages
-
Query to return all SQL statements ran for a particular user.
Good Morning,
Is it possible to find all the SQL statements run for a particular user using the v$ views? I can do it it 10g however I am currently using 9i and the query below does not work.
select a.username,a.logon_time,b.sql_fulltext
from v$session a,v$sqlarea b
where a.sql_id=b.sql_id
and a.username='USER'
order by a.logon_time descI assume some columns in these views do not exist in 9i. The release of 9 I am using is 9.2.0.1.0.
You help is much appreciated.
Thanks,
Mark.Dear Mark!
I suggest you to use auditing instead of v$sqlarea. Oracle Onlinedocumentation says the following about v$sqlarea:
>
V$SQLAREA lists statistics on shared SQL area and contains one row per SQL string. It provides statistics on SQL statements that are in memory, parsed, and ready for execution.
>
That means that you'll get only those SQL-Statements that are currently in memory. Older statements which are already deleted from memory are not visible for your query.
By the way if you simply want to know what is wrong with your query then please post your errormessage.
Yours sincerely
Florian W.
Edited by: Florian W. on 29.07.2009 12:03 -
Changing sql-statement before executing query
I want to change the sql-statement of a query just before it is executed.
I have tried it with a query redirector/sessionevent listener, but I could get it to work.
Do you have any examples.
I want to change the tablename in a sql-statement like this:
before
select id from emp
after
select id from emp_v
Any examples out there to do this?... I am using SAP NetWeaver BI 7.0
Monique -
SQL statement running balance query with previous balance taken into account
Hi Guys
I have a SQL statement which caclulates the running balance
for a list of transactions in a transactions table. This SQL
statement is as follows:
SELECT transID, debit, credit,
(SELECT SUM(debit-credit)
FROM transactions as D1
WHERE D1.transID <= D0.transID) AS balance
FROM transactions AS D0
The only problem I'm having is that I have to display
transactions between a particular date range. I have for eg.
transID, transDate, debit, credit fields in my db.
However the problem I'm having is that when the transaction
records are pulled out for the specified date range the balances
are only calculated for those records. I need someway of having a
balance b/f (brought forward) so that the selected records use that
as a 'starting' balance and then calculate the running balance as
normal.
Any easy solutions?
Many, many thanks for your help in advance.
All the best
WesleyYou'd need to determine the b/f then apply it against the
transaction records when they are pulled for a date range. So if
the date range is
Feb 1st, 2009 -> Feb 28th, 2009
You'd need to also get the previous balance in a separate
query, then use it to correctly display the running balance when
you output the date range.
I suppose a simpler way involving a little more DB work (and
possibly lots of coding) is to store the current balance as well
with each transaction; then when performing a date range you'd have
the balance as well and not have to calculate it on the fly. -
How to get SQL statement from (Collection) query.execute();
We have a JDO Persistence class ClassName that execute query using following code. After this statement get executed, record does not get updated in the DB. Is there a way to check what SQL statement got submitted in the (Collection) query.execute(); ??? <br><br>
Extent extent = pm.getExtent(ClassName.class, false); <br>
Query query = null; <br>
try { <br>
query = pm.newQuery(extent, filter); <br>
Collection results = (Collection) query.execute();<br>
Iterator i = results.iterator();<br>
if (i.hasNext()) {<br>
...<br>
}<br>You can always find out the names of tables that are views, using java.sql.DatabaseMetaData and its getTables() method.
This tends to be a nice source of examples:
javaalmanac.com
However, if you're asking for the underlying SQL used to CREATE VIEW, I don't see anything in the API that will give you that. After all, JDBC shouldn't have to know if it's dealing with an ordinary table or a view. I think you'd have to ask your DBA for the underlying SQL.
Once you have it, what do you plan to do with it?
% -
is there any chance to get the sql statement (not program) from any abap query created via SQ01?
I can get the code of program that generated by system, but I cannot get pure sql statement.
any answer will be appreciatedI see no parameters, and in the abstract that SQL ought to work.
However, I halfway suspect that either User, Users, Password, or pass is a reserved word and somebody is getting confused. Try renaming your columns and table... -
Hi all
Can we see the SQL statement of a BEx query, if so , where and how?
Thanks in advance.Yes, you can do that in transaction RSRT. Enter the query name, click the button "Execute & Debug" and click the checkbox for SQL code.
-
SQL Developer replacement for Query Builder?
Our developers use query builder to quickly develop sql code w/conditions, joins, where clauses, etc. I just installed release 2 of SQL Developer and am trying to figure out if this is a viable replacement for query builder. Is there a graphical "query builder" component as part of SQL Developer?
Barry, I would agree that it should be clean and easy to use. I started using Data Browser 2.0 and migrated to Query Builder 6.0.7.1.0 and while Query Builder is no longer it's own product it's integrated into Reports Developer 10g. The basic layout and operation has been consistent thru the life cycle and I would think you'd keep the "look and feel" consistent with what's currently available. (might simplify integrating it too). My biggest complaint with Query Builder 6.0.7 (se don't use the 10g version) is that it errors when opening a schema with more than 8192 objects. As an E-Business Suite 11.5.10 customer this is an issue for our developers when logging in as the standard APPS user.
So here would be my "wish list"
1. consistent look and feel with "older" versions of Browser/Query Builder
2. removal of 8192 object limitation
3. ability to open older .brw format files
Certainly more improvements would be possible by integrating with SQL Developer and would be welcomed - this wish list is coming from a user who has MANY .brw files in the older 6.0.7 format. -
Update sql help needed for hierarchy table
I am trying update the gross qty field based on each unit qty. This is how the table looks.
slevel | manager | seller |unit_qty | gross qty
0 | mary | mary | 1 | 1
.1 | mary | lynn| 3 | null
.1 | mary | betty | 2 | null
.1 | mary | alice | 2 | null
..2 | alice | susan | 1 | null
.1 | mary | amy | 4 | null
I would the table to look like this after the update, with the values
slevel | manager| seller | unit_qty | gross qty
0 | mary | mary | 1 | 1
.1 | mary | lynn| 3 | 3*1 ={color:#ff0000}3{color}
.1 | mary | betty | 2 | 2*1 ={color:#ff0000}2{color}
.1 | mary | alice | 2 | {color:#008000}2*1{color} ={color:#ff0000}2{color}
..2 | alice | susan | {color:#0000ff}1{color} | {color:#008000}2*1{color}{color:#0000ff}*1{color} ={color:#ff0000}2{color}
.1 | mary | amy | 4 | 4*1 = {color:#ff0000}4
{color}
This is the sql statement I tried to use without sucess.
update table set gross_qty = unit_qty * ({color:#ff0000}select gross_qty from table{color}
{color:#ff0000}where manager=seller{color})
where slevel >0Perhaps the old EXP (SUM (LN (n))) trick for calculating the product.
Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
SQL> CREATE TABLE seller (
2 manager VARCHAR2 (5),
3 seller VARCHAR2 (5),
4 unit_qty NUMBER,
5 gross_qty NUMBER);
Table created.
SQL> INSERT INTO seller (manager, seller, unit_qty) VALUES (NULL, 'mary', 1);
1 row created.
SQL> INSERT INTO seller (manager, seller, unit_qty) VALUES ('mary', 'lynn', 3);
1 row created.
SQL> INSERT INTO seller (manager, seller, unit_qty) VALUES ('mary', 'betty', 2);
1 row created.
SQL> INSERT INTO seller (manager, seller, unit_qty) VALUES ('mary', 'alice', 2);
1 row created.
SQL> INSERT INTO seller (manager, seller, unit_qty) VALUES ('alice', 'susan', 1);
1 row created.
SQL> INSERT INTO seller (manager, seller, unit_qty) VALUES ('mary', 'amy', 4);
1 row created.
SQL> COMMIT;
Commit complete.
SQL> SELECT manager, seller, unit_qty, gross_qty
2 FROM seller;
MANAG SELLE UNIT_QTY GROSS_QTY
mary 1
mary lynn 3
mary betty 2
mary alice 2
alice susan 1
mary amy 4
6 rows selected.
SQL> UPDATE seller s1
2 SET s1.gross_qty = (SELECT EXP (SUM (LN (s2.unit_qty)))
3 FROM seller s2
4 START WITH s2.seller = s1.seller
5 CONNECT BY s2.seller = PRIOR s2.manager);
6 rows updated.
SQL> SELECT manager, seller, unit_qty, gross_qty
2 FROM seller;
MANAG SELLE UNIT_QTY GROSS_QTY
mary 1 1
mary lynn 3 3
mary betty 2 2
mary alice 2 2
alice susan 1 2
mary amy 4 4
6 rows selected.
SQL> -
Help needed in SQL performance - Using CASE in SQL statement versus 2 query
Hi,
I have a requirement to find count from a bunch of tables.
The SQL I have gives the count of all members.
I have created 2 queries to find count of active and inactive members.
The key difference is only the active dates.
Each query takes 20 seconds to execute.
I modified the SQL to use CASE statement in the SELECT.
So after the data is fetched the CASE statement will evaluate the active date and gives 2 counts (active and inactive)
Is it advisable to use this approach. Will CASE improve SQL performance ? I have to justify this.
Please let me know your thoughts.
Thanks,
JHi,
If it can be done in single SQL do it in single SQL.
You said:
Will CASE improve SQL performance There can be both cases to prove if the performance is better or worse.
In your case you should tell us how it is.
Regards,
Bhushan -
SQL HELP NEEDED IN QUERY FOR COUNT
I Have this Query
SUM (CASE WHEN b.VET_OTHR_ELIG_CDE IN ('02', '03', '04') THEN 1 END) AS VET_YES,
SUM (CASE WHEN b.VET_OTHR_ELIG_CDE = '01' THEN 1 END) VET_NO, COUNT (E.ACTV_CDE) AS CNT_ACTV_CDE
Now i need to Add two more columns from the same Query Showing the count of VET_YES and VET_NO i.e count of TOTAL Veterans And TOTAL Non Veterans
those two columns i will be using as summary columns in my report.The bolded columns are those which i need to show the total column .anyone please help in this issue ..
ACTV_DESC ACTV_CDE VET_YES VET_NO CNT_ACTV_CDE
INACT DUE 13993 2 1 3
NOW I NEED TO MAKE IT LIKE THIS
ACTV_DESC ACTV_CDE VET_YES VET_NO CNT_VET CNT_NONVET CNT_ACTV_CDE (This is the total count)
INACT DUE 13993 2 1 2 1 3
Thanks in Advance,
Dev Kishore.T
Message was edited by:
Dev Kishore
Message was edited by:
Dev KishoreCheck this link.
http://download.oracle.com/docs/cd/B19306_01/server.102/b14223/aggreg.htm#sthref1612
Regards
Raj -
Hi,
I've select query to retrive the data in the following order
Sequnce ID Model Barcode
1 Dell 123
2 Dell 124
3 Dell 125
4 HP 126
5 hp 127
6 hp 128
7 apple 129
8 apple 130
I want the following to be selected round robin for Dell and Hp laptop alone as mentioned below.
Sequnce ID Model Barcode
1 Dell 123
4 HP 126
2 Dell 124
5 hp 127
3 Dell 125
6 hp 128
7 apple 129
8 apple 130
Can you help me to acheive this?
Thanks!Hi,
user601042 wrote:
Hi,
I've select query to retrive the data in the following order
Sequnce ID Model Barcode
1 Dell 123
2 Dell 124
3 Dell 125
4 HP 126
5 hp 127
6 hp 128
7 apple 129
8 apple 130If that's what you want, then it looks like
ORDER BY barcodeis all you need.
If you want the results sorted as below, Then you can use the analytic ROW_NUMBER function:
ORDER BY CASE
WHEN UPPER (model) IN ('DELL', 'HP')
THEN ROW_NUMBER () OVER ( PARTITION BY UPPER (model)
ORDER BY barcode
END
, barcode
I want the following to be selected round robin for Dell and Hp laptop alone as mentioned below.
Sequnce ID Model Barcode
1 Dell 123
4 HP 126
2 Dell 124
5 hp 127
3 Dell 125
6 hp 128
7 apple 129
8 apple 130Either way, I assume that sequnce id is not actually in your table.
Edited by: Frank Kulash on Mar 14, 2013 12:38 PM
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only), and also post the results you want from that data.
Explain, using specific examples, how you get those results from that data.
Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
See the forum FAQ {message:id=9360002} -
Help needed for Report Generator in B1 2005
Hi,
I have upgraded to B1 2005 and I would like to know where I can find Help files for the report generator (used to customize invoices ...). In particular, I would like to know where I can find information about the system functions available e.g. currentpage().
Thanks in advance for your help!
JPUse this link.
<a href="https://websmp102.sap-ag.de/form/sapnet?_FRAME=OBJECT&_HIER_KEY=701100035871000437965&_SCENARIO=01100035870000000183&">https://websmp102.sap-ag.de/form/sapnet?_FRAME=OBJECT&_HIER_KEY=701100035871000437965&_SCENARIO=01100035870000000183&</a>
In Customization section you can find a document based on PLD -
Hiding SQL statement in Query Result Window
Hi everyone,
Is it possible to hide the SQL statement from a query result window? This can usually be done by click the orange triangle that is positioned to the left of the SQL string box (to expand and collapse it). The System Queries have this box collapsed per default, is it possible to have this setup as default for all queries, including the custom? If so, please let me know where this can be done.
CheersYou should do this only with SDK programming - dont allow to show the syntax. The next, but problematic way, is the code you have do inside stored procedure and call only this sp inside the query generator window - if you have there some input parameters, you should use filling variables before executing sp and get it as input parameters to sp.
-
The number of reloads for the SQL statements
Hi,
in 10g R2, how to see the number of reloads for the SQL statements ? Any query ? Which value is high ? Which valu is low ?
Thanks.thanks all.
It was a test question for 1Z0-042 exam as follows :
The users on your SALESDB are complaining of slow response to their queries. Using the SQL Tuning Advisor, you determine
that the SQL statements are using the best optimization plan. Querying the dynamic views, you see that the number of reloads
for the SQL statements is high, which can cause performance degradation.
Which component of the SGA should you resize to reduce the number of reloads of the SQL statements?
Answer :
shared poolThen I wonder how to see the number of reloads for the SQL ?
Maybe you are looking for
-
How do I put this iMac back to factory settings?? Late 2013 model with Yosemite 10.10???
-
How do I get my iMessenger working on iPad and iPhone please?
My imessenger has stopped working on both my iPad 4 and iPhone 4. Any ideas? I have separate apple IDs for iTunes and iCloud/emails. Not sure if that makes a difference?! Thanks
-
Does iMovie 08 actually work at all?
Long story short, I was trying to make a dvd of some old movies of our family for my daughter's upcoming wedding. The movies are in .mpg format. iMovie won't import them as .mpg. After reading some articles and forum posts I googled, I've used MPEG S
-
Issue with drill down to FAGLB03
We have report painter reports that were linked to FS10n (Balance display) on the report interface (in the report library - GR22) so that when we drill-down on a line item in the report, it will show all the detail postings for that line item from FS
-
ANYONE KNOW WHAT I CAN USE TO CONNECT MY IPOD NANO TO AN AUX DEVICE SO I CAN LISTEN TO MY MUSIC THROUGH MY STEREO