Using conditions with SELECT
I am trying to gather conditional data from a table based on data from another as shown below :
SELECT NEW_ITEM.CD, CLIENT_DISCOUNT.SHOPPER_ID,
If CLIENT_DISCOUNT.DISCOUNT<=NEW_ITEM.MAX_DISC then NEW_ITEM.BASE_PRICE*((100-CLIENT_DISCOUNT.DISCOUNT])/100)Else NEW_ITEM.BASE_PRICE*((100-NEW_ITEM.MAX_DISC)/100) AS CAT_PRICE
End If
FROM NEW_ITEM, CLIENT_DISCOUNT
WHERE CLIENT_DISCOUNT.SHOPPER_ID='Ted';
but i am getting the error "FROM is not where expected".
So my questions are :
1. If it is possible to put If ... Then ... Else inside a Select query and
2. If yes, what is the correct syntax.
Thank you in advance.
You can use a CASE... END statement in SQL to achieve the desired result.
Your query would look something like this :
select n.cd, c.shopper_id, CASE WHEN c.discount <= n.max_disc THEN n.base_price*((100 - c.discount)/100)
ELSE n.base_price*((100 - n.max_disc)/100)
END as ItemPrice
from new_item n , client_discount c where c.shopper_id='Ted'
Ideally your query should have one more condition like n.itemId = c.itemId in the where clause to limit the
query results otherwise it will result in a cartesain product.
Chandar
Similar Messages
-
Hi experts,
I have a problem where i feel i should catch filtered resultset on to my internal table and i feel using LIKE.
But if i use LIKE '%AMIT%'
will it store
AMIT
amit
Amit ie all possible combination irrespectin of any case ?
Will it be case insenstive or not ?HI,
using like in select is case sensitive.
do like this for ignoring the case.
TABLES:mara.
SELECT * from mara.
IF mara-matnr cp 'm*'.
WRITE:/ mara-matnr.
ENDIF.
ENDSELECT.
rgds,
bharat. -
Trying to use Spry with Select List
I have a dataset that is static xml. .In the xml file I have
a node called categoreis and then repeating node of store name,
phone and address in that category. There are around 15 categories
and a total of 100 stores with address and phone. I can create the
select list and add the onchange event to tell Spry which row of
data was selected in the drop down. I do not understand how to
generate the detail region that shows the stores for that
particular category. Any help would be appreciated.Always include the following information when asking a question:
<ul>
<li>Full APEX version</li>
<li>Full DB/version/edition/host OS</li>
<li>Web server architecture (EPG, OHS or APEX listener/host OS)</li>
<li>Browser(s) and version(s) used</li>
<li>Theme</li>
<li>Template(s)</li>
<li>Region/item type(s)</li>
</ul>
taepodong wrote:
Hi All,
Bit at loss what i am doing wrong here. Trying to change a field (previously in textfield) to a drop down select list. All works except one. It looks like Multi-selector even though I set the type as Select List
http://i.imgur.com/Hz7tP.png
Got no idea what I have to do to change it to drop down. Many Thanks.If you are on apex 4.x, you might have set the Allow Multiple Selection to Yes
Edit the select list item > Settings > set Allow Multi Selection to No
http://docs.oracle.com/cd/E23903_01/doc/doc.41/e21674/item_types001.htm#HTMDB28627 -
Using Keyfigures with selections in a query
Hi Experts,
I am designing a query which has the selection criteria as (Condition1) OR ( Condition2 and Condition3) and all the selection are for a single month. For this I have created a Structure and am using two selections.
I also need to display a SINGLE keyfigure which displays the number of records for the month. The problem that I am facing is, as soon as I hide the selections the Keyfigure values do not show up.
Any ideas.
Thanks
RBHi Vijay,
Though it should not make a difference whether the result values are suppressed or not because I am using selections in a structure but still I tried this and it did not work. Let me redefine my problem to ease the understanding of the logic.
select all sales order whose (priority is high) OR ( status is inprocess And owner = X)
For the above criteria I created one selection which had the restriction on Priority as high and the other selection has status as inprocess and Owner = X.
Now I do not want to show the selection criteria on the report so I have hidden both the selections.
I also want to display a keyfigure which counts the number of records.
The problem is If I hide the selections it does not display the number of records but If I show the selections then it does. I do not want to display the selections but still do want the number of records value to appear.
I hope this time I was more clear.
Thanks
RB -
Receiver Determination, condition to select receiver doesn't extract values
Dear all!
I have SAP PI 7.1
I am facing problem in Receiver Determination while using Condition to select receiver based on the values in the payload.
I need, if Identificador = 1 then receiver BC_1 and if Identificador = 2 then the receiver BC_2
My payload has the value:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:p1="http://pruebas.endesa.es/AME4S_2">
<soap:Body>
<p1:MT_WS_SENDER_Q>
<IDENTIFICADOR>1</IDENTIFICADOR>
<OBJECT_ID>7600000009</OBJECT_ID>
</p1:MT_WS_SENDER_Q>
</soap:Body>
</soap:Envelope>
But, the trace shows following:
<Trace level="2" type="T">......extracting (new) for Extractor: XP /p1:MT_WS_SENDER_Q/IDENTIFICADOR </Trace>
<Trace level="2" type="T">......extracting values found: 0 </Trace>
I tried with double quotes, simple quotes, without quotes...
I tried too with a Receiver Rule (with context) and local rule with xpath....
Can someone please advise?
Thanks in advanced!!Hello,
/p1:MT_WS_SENDER_Q/IDENTIFICADOR = 1
Can you try //p1:MT_WS_SENDER_Q/IDENTIFICADOR = 1 ? I'm sure I read it somewhere here in SDN regarding the xPath difference for stateless and stateless XI 3.0 compatible version is an additional /. It's worth to try
Hope this helps,
Mark -
Using record with sql in clause
hi friends
i have a record and which have only some id's. and i have to use it with select in
like
Select * from aaaa where id in record
how can we do it?JAVAMAN2 wrote:
hi friends
i have a record and which have only some id's. and i have to use it with select in
like
Select * from aaaa where id in record
how can we do it?Well, a record is certainly better-er than an eight track, so you're on your way, soon you'll have a CD, then a DVD, unless you deviate and end up with a Laser Disc.
Now, how about you post some technically relevant information describing in great detail 1) what you have and 2) what you want.
For the former, you would want to tell us your oracle version
select * from v$version;And all the pertinent information (technically speaking), as well as what you expect and why.
If you can't take the time to post a thorough question, how can you expect anyone to provide a thorough (and correct) answer? -
Using where condition with dynamic internal table
Hi Friends.
How to use where condition with dynamic internal table ?
Regards,
Amit RautHai Amit
REPORT ZDYNAMIC_SELECT .
TABLES: VBAK.
DATA: CONDITION TYPE STRING.
DATA: BEGIN OF ITAB OCCURS 0,
VBELN LIKE VBAK-VBELN,
POSNR LIKE VBAP-POSNR,
END OF ITAB.
SELECT-OPTIONS: S_VBELN FOR VBAK-VBELN.
CONCATENATE 'VBELN' 'IN' 'S_VBELN.'
INTO CONDITION SEPARATED BY SPACE.
SELECT VBELN POSNR FROM VBAP INTO TABLE ITAB
WHERE (CONDITION).
LOOP AT ITAB.
WRITE 'hello'.
ENDLOOP.
Thanks & Regards
Sreenivasulu P -
Can we use 2 Conditions as Selection Variables in a Query?
Hi Gurus,
According to the requirement in our report , we need to have selection variables on 2 Key figures Target Quantity and Consumption.
So ,we have used Conditions to have Variables in the Selection screen.
The Conditions (the Selection screen variables) are not working properly.
Can you please give some pointers on the Conditions to be used in the reports.
Thanks,
SravaniI did not understand whats the issue is...., is it with the condition? or the variable.
If with the Condition please provide some more details about the condition.
If it is a variable, as the other person said, how did you create the variable on the Keyfigure? because as per i know we cannot create any variable for the Keyfigure, but if is possible please let me know, and i can dig in to that, and let you know how to fix the issue.
Regards,
Ram
Edited by: Ram Pawan on Aug 14, 2008 4:06 PM -
OPEN CURSOR using a WITH clause in the select query
Hi,
I am using Oracle 9i. I have a requirement where I have a REFCURSOR as an OUT parameter for my procedure. I have declared the TYPE and created the procedure.
In the procedure, I am using OPEN <cursor_name> FOR <query>;
Ideally this works in most of the cases that I have tried earlier. However, in the current case I am using a WITH clause in my query to get the results.
I need help in understanding if the above mentioned syntax would not allow me to use the WITH clause in the query.What error do you get , seems to work ok for me on 10g
SQL> begin
2 open :cv for 'with x as (select * from emp) select * from x';
3 end;
4 /
PL/SQL procedure successfully completed.
SQL> print :cv
EMPNO
ENAME
JOB MGR HIREDATE SAL COMM DEPTNO
7521
WARD
SALESMAN 7698 22-FEB-81 1250 500 30
7566
JONES
MANAGER 7839 02-APR-81 2975 20
EMPNO -
How do i use conditional formatting to edit the color of other selected other cells?
I have been playing around with the conditional formatting feature of Numbers, I have figured out how to change font and background color of the cell i am working with.
However what i am looking to do is apply a background color formatting to another cell (i.e. F2) if conditions are met in (B2).
the end game is this,
I want to make a column of check boxes, and using contional formating i want adject cells to change color (I.e. the example above: if (B2) is a check box, then when unchecked the reffered Cell (F2) does nothing, but when check the color of (F2) changes)
I can make this happen with Logic equations, the give (i.e. F2) some letter or number value, then using conditional formats i can have the color change. but this leaves that particular cell useless to me (i.e. F2) I am not free to enter or edit text in that cell. (i.e. =IF(B2=TRUE,"Paid","Due") ----> then add a conditional statement that chages color when the value is either "Paid" or "Due")
How do i have F2 change color, when B2 is checked and still retain the ability to enter information (or potential have another formula) in F2? (The Cell is not used up by "Paid" or "Due" it is editable just like any other cell)
is there anyway to change cell characteristics like font, color, and background color inside a formula, because in that way i would be able build it manually
i tried using the formula editor inside the conditional format pane, but the only infor it will allow me to retain is one partictular cell. i cannot add modifiers like "+" or "=" or anything else. what is that space used for then?
thanks for anyones helpMC,
You can do what you want in Numbers. It requires an auxiliary column and it's a bit tedious to set up because conditional formatting by comparison to another cell isn't relative, so each cell has to be programmed individually with no option to Paste or Fill to other cells in a range.
For explanation purposes, let's say your checkbox is A2, your cell to be conditionally formatted is B2, and your auxiliary cell is C2. To have the format of B2 determined by the checkbox status in A2, you will:
1. In C2 write: =IF(A, B, " ") The " " is any string or value that you don't expect to encounter in B normally, and using the space character means you don't have to worry about having it visible if C is in View.
2. In B2 use Conditional Format: "Equal To" cell C2 and set your text and fill attributes to be used when the box in A is checked.
That's it. Do that for every cell in the range.
Jerry -
How can i use index in select query.. facing problem with the select query.
Hi Friends,
I am facing a serious problem in one of the select query. It is taking a lot of time to fetch data in Production Scenario.
Here is the query:
SELECT * APPENDING CORRESPONDING FIELDS OF TABLE tbl_summary
FROM ztftelat LEFT JOIN ztfzberep
ON ztfzberep~gjahr = st_input-gjahr
AND ztfzberep~poper = st_input-poper
AND ztfzberepcntr = ztftelatrprctr
WHERE rldnr = c_telstra_accounting
AND rrcty = c_actual
AND rvers = c_ver_001
AND rbukrs = st_input-bukrs
AND racct = st_input-saknr
AND ryear = st_input-gjahr
And rzzlstar in r_lstar
AND rpmax = c_max_period.
There are 5 indices present for Table ZTFTELAT.
Indices of ZTFTELAT:
Name Description
0 Primary key( RCLNT,RLDNR,RRCTY,RVERS,RYEAR,ROBJNR,SOBJNR,RTCUR,RUNIT,DRCRK,RPMAX)
005 Profit (RCLNT,RPRCTR)
1 Ledger, company code, account (RLDNR,RBUKRS, RACCT)
2 Ledger, company code, cost center (RLDNR, RBUKRS,RCNTR)
3 Account, cost center (RACCT,RCNTR)
4 RCLNT/RLDNR/RRCTY/RVERS/RYEAR/RZZAUFNR
Z01 Activity Type, Account (RZZLSTAR,RACCT)
Z02 RYEAR-RBUKRS- RZZZBER-RLDNR
Can anyone help me out why it is taking so much time and how we can reduce it ? and also tell me if I want to use index number 1 then how can I use?
Thanks in advance.Hi Shiva,
I am using two more select queries with the same manner ....
here are the other two select query :
***************1************************
SELECT * APPENDING CORRESPONDING FIELDS OF TABLE tbl_summary
FROM ztftelpt LEFT JOIN ztfzberep
ON ztfzberep~gjahr = st_input-gjahr
AND ztfzberep~poper = st_input-poper
AND ztfzberepcntr = ztftelptrprctr
WHERE rldnr = c_telstra_projects
AND rrcty = c_actual
AND rvers = c_ver_001
AND rbukrs = st_input-bukrs
AND racct = st_input-saknr
AND ryear = st_input-gjahr
and rzzlstar in r_lstar
AND rpmax = c_max_period.
and the second one is
*************************2************************
SELECT * APPENDING CORRESPONDING FIELDS OF TABLE tbl_summary
FROM ztftelnt LEFT JOIN ztfzberep
ON ztfzberep~gjahr = st_input-gjahr
AND ztfzberep~poper = st_input-poper
AND ztfzberepcntr = ztftelntrprctr
WHERE rldnr = c_telstra_networks
AND rrcty = c_actual
AND rvers = c_ver_001
AND rbukrs = st_input-bukrs
AND racct = st_input-saknr
AND ryear = st_input-gjahr
and rzzlstar in r_lstar
AND rpmax = c_max_period.
for both the above table program is taking very less time .... although both the table used in above queries have similar amount of data. And i can not remove the APPENDING CORRESPONDING. because i have to append the data after fetching from the tables. if i will not use it will delete all the data fetched earlier.
Thanks on advanced......
Sourabh -
Delete statement that uses a sub-select with the statement in the cursor
Hi all,
How to write write a delete statement that uses a sub-select with the statement in the cursor?
CURSOR excluded_dates IS
SELECT TO_TIMESTAMP(report_parameter_value, in_date_format_mask)
INTO my_current_date_time
FROM report_parameters
WHERE report_parameters.report_parameter_id = in_report_parameter_id
AND report_parameters.report_parameter_group = 'DATE_TIME'
AND report_parameters.report_parameter_name = 'EXCLUDED_DATE';
OPEN excluded_dates;
LOOP
FETCH excluded_dates INTO my_excluded_date;
EXIT WHEN excluded_dates%NOTFOUND;
DELETE FROM edr_rpt_tmp_inclusion_table
WHERE TO_CHAR(date_time, 'mm/dd/yyyy') = TO_CHAR(my_excluded_date, 'mm/dd/yyyy');
END LOOP;
CLOSE excluded_dates;ThanksHi,
In such case I think is better to create a view an perform the delete using it. Example (using HR schema):
Connected to Oracle Database 10g Express Edition Release 10.2.0.1.0
Connected as hr
SQL> create or replace view v_employees as select * from employees where first_name like 'J%';
View created
SQL> select * from v_employees;
EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
110 John Chen JCHEN 515.124.4269 28/09/1997 FI_ACCOUNT 8200,00 108 100
112 Jose Manuel Urman JMURMAN 515.124.4469 07/03/1998 FI_ACCOUNT 7800,00 108 100
125 Julia Nayer JNAYER 650.124.1214 16/07/1997 ST_CLERK 3200,00 120 50
127 James Landry JLANDRY 650.124.1334 14/01/1999 ST_CLERK 2400,00 120 50
131 James Marlow JAMRLOW 650.124.7234 16/02/1997 ST_CLERK 2500,00 121 50
133 Jason Mallin JMALLIN 650.127.1934 14/06/1996 ST_CLERK 3300,00 122 50
139 John Seo JSEO 650.121.2019 12/02/1998 ST_CLERK 2700,00 123 50
140 Joshua Patel JPATEL 650.121.1834 06/04/1998 ST_CLERK 2500,00 123 50
145 John Russell JRUSSEL 011.44.1344.429268 01/10/1996 SA_MAN 14000,00 0,40 100 80
156 Janette King JKING 011.44.1345.429268 30/01/1996 SA_REP 10000,00 0,35 146 80
176 Jonathon Taylor JTAYLOR 011.44.1644.429265 24/03/1998 SA_REP 8600,00 0,20 149 80
177 Jack Livingston JLIVINGS 011.44.1644.429264 23/04/1998 SA_REP 8400,00 0,20 149 80
181 Jean Fleaur JFLEAUR 650.507.9877 23/02/1998 SH_CLERK 3100,00 120 50
186 Julia Dellinger JDELLING 650.509.3876 24/06/1998 SH_CLERK 3400,00 121 50
189 Jennifer Dilly JDILLY 650.505.2876 13/08/1997 SH_CLERK 3600,00 122 50
200 Jennifer Whalen JWHALEN 515.123.4444 17/09/1987 AD_ASST 4400,00 101 10
16 rows selected
SQL> delete from v_employees where hire_date >= to_date('01/06/1998', 'dd/mm/yyyy');
2 rows deleted
SQL> regards, -
I've been using LR with my Nikon D3200 for a year or so. Shooting in RAW/NEF no issues with import etc until I updated LR and now I can't get LR to allow me to select when I try to import. It does show the images but they're grayed out and not able to be selected. Any thoughts? TIA
Greyed imaged in the Import dialog box mean you have already imported the photos into Lightroom, so there is no need and no benefit to importing them a second time.
Just go to the Library module, search for the desired photos, and resume working on these photos. -
Is it possible to delete a plot with using mouse to select it on the graph control?
For example, when I use PlotLine to plot thousands of lines on the graph control, I want to delete some of them, but there is thousands of plotHandle generated.
How can I get the plotHandle of the specific line on the graph control with using mouse to select it?
If I record information of the lines, ex. the plotHandle and the coordinates, on a table or list, etc. , I have to compare the information of lines to get the plotHandle of the specific line.
Is there any user-friendly way to delete a plot by select it on the graph control?
Solved!
Go to Solution.Sure! Look at the example located in \samples\userint\graphcursors for an example of how to accomplish this task.
Briefly:
The cursor must be in "Snap to point" mode
(To be confirmed) The graph must be in "Retain" data mode
You must have a callback for the graph control
You can use GetGraphCursorIndex to retrieve the plot handle
GetGrpahCursor retrieves values of cursor position in engineering units
Proud to use LW/CVI from 3.1 on.
My contributions to the Developer Zone Community
If I have helped you, why not giving me a kudos? -
Want to use ldb selection screen with select queries
I want to use ldb selection screen with select queries since ldb having performance issue .How can I use the fields of the dynamic selection of LDB in the select queries
Hi,
Check the code snippet below: Here 'XXXX' is the table for your select query.
DATA L_DS_CLAUSES TYPE RSDS_WHERE.
MOVE 'XXXX' TO L_DS_CLAUSES-TABLENAME.
READ TABLE DYN_SEL-CLAUSES WITH KEY L_DS_CLAUSES-TABLENAME
INTO L_DS_CLAUSES.
SELECT * FROM XXXX
WHERE field1 IN ...
AND field2 ....
AND (L_DS_CLAUSES-WHERE_TAB).
PUT XXXX.
ENDSELECT.
You can also try using the FM 'RS_REFRESH_FROM_DYNAMICAL_SEL' passing SY-CPROG in curr_report and 'M' for mode to get the dynamic selection screen values.
Regards,
Munesh.
Maybe you are looking for
-
I have created a cifs share that is being accessed by Mac users that are part of a windows 2003 AD. When the user edit data and save it back to the share, the security permission are reset and none of the other users can see the new data unless the
-
hi, Could you please suggest some Function Modules that convert data from Quarterly basis to weekly basis
-
Hi All We want to block the sales order based on Previous AR Invoice. We have a UDF In AR Invoice . If the Value of UDF is NULL then user cannot able to enter the new sales Order for that particular customer. If somebody can help me in SP Notificatio
-
The confirmation # is AD014846990 and order date is Nov. 23, 2014. Please advise asap. Mike Hickey
-
LR2.7 does not bring up images from Nikon D7100
LR 2.7 does not bring up images from Nikon D7100 which I have just purchased. I have downloaded latest DNG raw converter 7.4 but does not work. The images come through fine in Bridge but not Lightroom. What is the problem?