Use an Alias in a statement Where clause
I use the Report Builder in CF10.
I need to select data from multiple tables. One of the conditions is that the term_int (201508 value is converted to school year) = sch_years (201516) in another table.
Here's my query:
/ * New student ready find out * /.
SELECT name.first_name, name.last_name, name.mi, name.soc_sec, name.name_le1, finaideurekaawddesc.finaideurekaawddesc AS AwardDesc, MMTemp.st_addr, MMTemp.add_addr, MMTemp.city, MMTemp.state, MMTemp.zip, MMTemp.Operator, finaideurekaawd.finaideurekaawdtot AS AwdAmt, nmact.act_memo, / * AS tuition, nmbudget_RM_BRD AS RoomBoard, nmbudget.nmbudget_tuition * / position.val AS post
CASE
WHEN SUBSTRING (MMTemp.term_int, 5.2) = '08' and then 'fall '.
ELSE 'spring' END as EntryPeriod,
CASE
WHEN SUBSTRING (MMTemp.term_int, 5.2) = '08' then LEFT(finaideurekaawd.sch_years,4)
Else (LEFT(finaideurekaawd.sch_years,2) + RIGHT(finaideurekaawd.sch_years,2)) END as EntryYear,
CASE
WHEN finaideurekaawddesc.finaidawdcat_cod like '% E' GOLD finaideurekaawddesc.finaidawdcat_cod as "OT" and THEN "Gift aid & schlorships.
WHEN finaideurekaawddesc.finaidawdcat_cod = 'FG' THEN 'need based aid.
WHEN finaideurekaawddesc.finaidawdcat_cod = "FL" AND "federal ready direct.
ELSE 'work study' END as CatType,
CASE WHEN name.camp_cod = "AdultLearn" THEN 17911 20510 to OTHER END AS tuition,
CASE WHEN name.name_le1 = 0 THEN 8835 ELSE 0 END AS RoomBoard
Finaideurekaawd, name, MMTemp, nmact, finaideurekaawddesc / *, nmbudget * /.
CROSS APPLY
(
SELECT
CASE
WHEN SUBSTRING (MMTemp.term_int, 5.2) = '08' then (LEFT (MMTemp.term_int, 4) + SUBSTRING (MMTemp.term_int, 3, 2) + 1).
ELSE (LEFT (MMTemp.term_int, 4-1) + SUBSTRING (MMTemp.term_int, 5.2)) END as val
OF MMTemp
) SchYr
AS the position
WHERE (MMTemp.Operator = ' #session.token # ' OR SUBSTRING('#session.token#',2,10) AS MMTemp.Operator)
AND MMTemp.soc_sec = name.soc_sec
AND MMTemp.soc_sec = nmact.soc_sec
AND MMTemp.activity_cod = 'AM'
AND SchYr.val = finaideurekaawd.sch_years
AND MMTemp.soc_sec = finaideurekaawd.soc_sec
/ * AND MMTemp.soc_sec = nmbudget.soc_sec * /.
AND MMTemp.activity_cod = nmact.activity_cod
AND finaideurekaawd.finaidawddesc_cod = finaideurekaawddesc.finaidawddesc_cod
AND nmact.act_date = (SELECT MAX (nmact.act_date) from nmact where nmact.soc_sec = MMTemp.soc_sec and nmact.activity_cod = 'AM' group by nmact.soc_sec, nmact.activity_cod)
I get an "incorrect syntax near the keyword 'CASE' error. I am open to any suggestion.
Cozmo2 wrote:
How can I move this question on a forum database?
Copy the text of your question and paste it into a new message in a forum database; preferably a forum which deals specifically with your database engine.
See you soon
Eddie
Tags: ColdFusion
Similar Questions
-
Hello
It is a question of OCA certification.
1. SQL > SELECT prod_name, prod_list_price, prod_list_price-(prod_list_price*.25) "DISCOUNTED_PRICE".
PRODUCTS
WHERE the discounted_price < 10;
The query generates an error.
What is the reason for generating fault?
A. the parentheses should be added to frame the entire expression
B. the quotes should be removed from the column alias
C. column aliases must be replaced by the expression in the WHERE clause
D. column aliases must be capitalized and closed double quotes in the WHERE clause
Answer: D
My question is how we can use aliases ("DISCOUNTED_PRICE") in where clause (WHERE "DISCOUNTED_PRICE" < 10)?
Please specify.Hello
C. response (and I think, you not write review at this time)
You cannot use alias name in the WHERE clause.
And if you want to continue to use DISCOUNTED_PRICE in the WHERE clause, you can use view inline.
SELECT * FROM (SELECT prod_name,prod_list_price,prod_list_price-(prod_list_price*.25) "DISCOUNTED_PRICE" FROM products ) WHERE WHERE discounted_price<10;
See you soon,.
Suri -
Dear friends,
Is there a way to access some of the columns using dblink but without using the quotes?
and also where clause without use of quote?
Please guide me
Thank you very much
Nithuser645399 wrote:
But is it possible to access Oracle's SQL Server using dblink without quotes to select columns?YES, it is possible, but the table names and column names must be UPPERCASE only
-
How to use a function in a Where Clause?
Hello
I have a doubt. If MY_FUNCT is a function that returns a Boolean value, can I use in a where clause clause to write a query like this? :
Select...
table one
where the...
*...*
and MY_FUNC (a.field) = true
*...*
*;*
Thank you!
Published by: Mark1970 on 3.27 lug-2-2010But is it possible that the function does not return a Boolean value?
Yes (as sysdate, substr and instr etc.) you can also use your own function in a where clause clause, as long as it does not return a BOOLEAN value.
I mean how to use a function in a where clause clause?
Your own pseudocode seems a good example for me.
So, just give it a try. -
Where-Clause-Question by using "defined values.
Hello
I use 10 gr 2
It is possible to filter the lines using sets of values in the where clause?
As for example:
.. must retrieve only the rows from myTable with sets (pairs) over the top of the listSELECT a, b, c FROM mytable WHERE (b,c) IN ( (3,4), (6,7), (9,1), (0,2) )
It is not difficult to test:
with my_tab as (select 1 a, 2 b, 3 c from dual union all select 2 a, 2 b, 2 c from dual) select * from my_tab where (b, c) in ((1,2), (2,3)); A B C ---------- ---------- ---------- 1 2 3
-
where clause to query the hierarchy in the tree Apex area does not
Hi all
I am building a tree Menu in Apex 5.0.3 (Oracle 11 g XE), when using when the clause, it does show all the data, but without him, showing all the data.
I'm trying to populate Tree Menu with data specific to a user successfully logged on.
(A) table created as HR2. TREE_MENU
menu_name varchar2 (50).
number of menu_parent
number of menu_child
menu_id varchar2 (12),
menu_path varchar2 (100),
number of user_no
(B) SQL statement for the tree in the Apex region
Select case when connect_by_isleaf = 1 then 0
When level = 1 then 1
else -1
end the status,
level,
'Menu_name' as the title,
NULL as an icon,
"MENU_CHILD" as a value.
NULL as ToolTip,
NULL as link
to HR2. "" TREE_MENU ".
-WHERE USER_NO =: P_USERNO
Start with 'MENU_CHILD' is null
connect prior "MENU_PARENT" = "MENU_CHILD."
brothers and sisters of order by 'MENU_ID '.
Note: also used static value where clause but is not workd.
that the mistake of me or something else? When using the wizard, she asks (possibly) where clause, this means that when the clause can be used in the SQL statement.
Help, please.
Kind regards.
If you want to prune your tree to show only the elements of the No. 7 usermenu, copy the following code helps you
select case when connect_by_isleaf = 1 then 0 when level = 1 then 1 else -1 end as status, level, "MENU_NAME" as title, null as icon, "MENU_CHILD" as value, null as tooltip, null as link from HR2."TREE_MENU" start with "MENU_CHILD" is null connect by prior "MENU_PARENT" = "MENU_CHILD" and "USER_NO" = 7 order siblings by "MENU_ID"
Concerning
Mahmoud
-
Hello
I want to use where clause in the View with BindVeriable object.
How can I use?
Concerning
Kiran SANCHEZYou cannot use Oracle bind variables when you use DB2. Use JDBC positional Binding Style in your query. You can use something like this in your where clause:
Where Field1 =? AND Field2 =?
Then set the 2 variables bind bind positions 0 and 1.
Make sure that you used DB2 Sql-flavor and a Java type map when creating business logic of your application (the first time you create a component of business adf).
-
Expand the view read-only object where Clause
Hello
Is there a way I can add another where, condition of the clause to a viewobject unalterable in my bean limit support more query? The view object has a where clause itself clause which I want to thank. However, it is not editable or based on an entity object.Hello
You can use ViewCriteriaRow to add where clause dynamically.
http://download.Oracle.com/docs/CD/E15051_01/apirefs.1111/e10653/Oracle/JBO/ViewCriteriaRow.html
In addition, you can also use a variable binding in the where clause and use setWhereClauseParams method before calling executeQuery.
http://download.Oracle.com/docs/CD/E15051_01/apirefs.1111/e10653/Oracle/JBO/ViewObject.html#setWhereClause (java.lang.String)
HTH.
Arun-
-
With the help of a list in a clause Where Clause
I try to use a dynamic list, in a where clause clause, not having much luck and we tried different ways.
Here's the closest thing I can find, the only problem is that the output returns an error caused by comma in where criteria if the list contains several items.
Any help would be greatly appreciated!
SELECT is the name of my list by commas.
< name cfquery = 'list' datasource = "#dbnm #" >
SELECT *.
Students
When status = ' #x # ' and (id = #Listqualify(select,"") #)
< / cfquery >When the use of lists in sql, you do not use an equal sign. You use the key word in. You must also put your list in parentheses.
-
pl/sql is it possible to put the cursor in where clause?
Hello
I have this stored proc that works very well when it is passed a single ID... now he must pass a list of IDS as in
function (cursor (select id from table))...
its definition is like this:
RETURN ACTIV_PKG.tADR_ACTIV PIPELINED IS function ADR_ACTIV (pi_NO_SEQ IN sys_refcursor)
CURSOR c1 (p_NOSEQ IN sys_refcursor) IS
WITH Lateststate AS
(SELECT RESUM_ETA.NO_SEQ_CLE_PRIM NO_SEQ_ADR,
ADR.NO_SEQ,
RESUM_ETA. COD_ETA
OF RESUM_ETA
JOIN INTERNAL ADR
ON ADR.NO_SEQ_ADR = RESUM_ETA.NO_SEQ_CLE_PRIM
WHERE RESUM_ETA. COD_TBL = "ADR1".
and IN ADR.NO_SEQ (p_NOSEQODS)
)...
You see that 'and ADR.NO_SEQ IN (p_NOSEQODS)' lines using only those on the list filters...
the idea is to use the cursor c1 like this:
BEGIN
FOR rec1 IN c1 (pi_NO_SEQ)
LOOP
...
Except that I get an error with (p_NOSEQODS) because it is not supported...
y at - there a trick to this?
Should I use table instead of cursor in where clause IN (...)?
I have not in a list of IDS and put it in where clause of my cursor c1... How to get there?
Thanks for the advice/links
See you soon!the idea is to use the cursor c1 like this:
FOR rec1 IN c1 (pi_NO_SEQ)Don't know if it's really less awkward that solution regexp, but we here are:
cur sys_refcursor; cursor c2 (cur sys_refcursor) is select * from emp where empno in (select trim (t.column_value.extract ('//text()')) from table (xmlsequence (cur)) t); begin open cur for select 7788 from dual union all select 7900 empno from dual; for c in c2 (cur) loop dbms_output.put_line (c.ename); end loop; end; / SCOTT JAMES PL/SQL procedure successfully completed.
-
Can I use truncated and where clause in the statement even?
Hello guys,.
Can I use truncated with where clause in the same statement.
For ex:
TRUNCATE TABLE my_table WHERE id < 500;
If not, that you recommend me to overtemperature to the level of high water line?
By the way
Oracle Database 11 g Enterprise Edition Release 11.2.0.1.0 - 64 bit Productionselect * from v$version;
PL/SQL Release 11.2.0.1.0 - Production
"CORE 11.2.0.1.0 Production."
AMT for 64-bit Windows: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
>
Thank you very much.
Published by: 970992 on 11:14 13.Ara.2012>
Okay I need an increasing amount of space. However, at the same time I want to recover the spaces empty below HWM. So, I need to use less amount of space I am inserting. Therefore, shouldn't use retractable for this?
>
Why waste the effort. Oracle will reuse the space below the HWM when doing inserts. You already said that you insert more lines you delete so all these will be more accustomed to the top.The only time where that oracle may not use space is when the space is too small to be useful. It is documented in the doc, I told you
>
Understanding recoverable unused space
Over time, Update, and Delete on objects within a tablespace can create pockets of empty space that individually are not large enough to be reused for the new data.
>
Most uses of CONTRACTION I've seen are totally useless. If you follow the doc and run the Advisor of segment it will tell you if there is space that can be retrieved and how much. But, even once, for your use even if case will get you will Oracle while you need to reassign the new extensions, then the HWM will just go still higher.If pay you a heavy price in Oracle did a full table scan, update of many blocks from the table, update THE index, impact performance for other users to access the table during the SHRINK and reallocate extensions (maybe even some of the same areas) when you insert more data.
Do not SHRINK unless you know it's necessary.
-
using case when statement or decode unfavorable in where clause
Hi the gems...
I have a problem in the following query...
I try to use when case statement in where clause of a select query.
Select cr.customer_name. ' - ' || CR.customer_number as cust_name,
CR. Salary salary
of customer_details cr
where (case when ' > ' = ' > ' then ' cr.salary > 5000')
When ' > ' = ' < ' then ' cr.salary < 5000'
When ' > ' = '=' and then 'cr.salary = 5000'
Another null
(end);
the expression in the when clause of the statement of the case, when comes from HQ and according to the choice I have to make the where clause.
That is why, for the execution of the query, I put ' > ' in this place.
If the original query will look like this (for reference):
Select cr.customer_name. ' - ' || CR.customer_number as cust_name,
CR. Salary salary
of customer_details cr
where (case when variable = ' > ' then ' cr.salary > 5000')
When the variable = ' < ' then ' cr.salary < 5000'
When the variable = '=' and then 'cr.salary = 5000'
Another null
(end);
so, in a real case, if the user selects ' > ' then the filter will be ' where cr.salary > 5000.
If the user selects ' < ' then the filter will be ' where cr.salary < 5000.
If the user selects '=', then the filter will be 'where cr.salary = 5000 '.
but I get the error "ORA 00920:invalid relational operator.
Help, please... Thanks in advance...Hello
select cr.customer_name || ' - ' ||cr.customer_number as cust_name, cr.salary as salary from customer_details cr where ( v_variable = 'bigger' and cr.salary > 5000 ) or ( v_variable = 'less' and cr.salary < 5000 ) or ( v_variable = 'eq' and cr.salary = 5000 )
Published by: user6806750 on 22.12.2011 14:56
For some reason that I can't write in sql "<', '="">", "=".',>
-
Tuning - using the CASE statement in the WHERE clause of the query
Hi all
My request has been changed to use a CASE statement in the WHERE clause to examine the data to some columns based on a parameter value. This modified request is made a full table and constantly running scan. Please suggest what can be done to improve its performance:
Query:
Description of the table:SELECT LAST_DAY(TRUNC(TO_TIMESTAMP(os.requestdatetime, 'yyyymmddhh24:mi:ss.ff4'))) AS summary_date, os.acctnum, os.avieworigin_refid, COUNT(1) cnt_articleview, SUM(NVL(autocompletedterm,0)) cnt_autocompletedterm FROM TABLE1 os WHERE os.acctnum IS NOT NULL AND os.avieworigin_refid IS NOT NULL AND os.requestdatetime IS NOT NULL AND UPPER(os.success_ind) = 'S' AND CASE WHEN Param_ValueToCheck = 'FULL' AND get_date_timestamp(os.requestdatetime) BETWEEN TO_DATE('01-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') AND TO_DATE('31-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') THEN 1 WHEN Param_ValueToCheck = 'INCR' AND os.entry_createddate BETWEEN TO_DATE('01-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') AND TO_DATE('31-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') THEN 1 END = 1 AND CASE WHEN Param_ValueToCheck = 'FULL' AND os.entry_CreatedDate BETWEEN TO_DATE('01-APR-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') AND TO_DATE('07-JUN-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') THEN 1 WHEN Param_ValueToCheck = 'INCR' THEN 1 END = 1 GROUP BY LAST_DAY(TRUNC(TO_TIMESTAMP(os.requestdatetime, 'yyyymmddhh24:mi:ss.ff4'))), os.acctnum,os.avieworigin_refid;
(Number of lines: approx. > amount 600 000 000)
Explain PlanName Null Type ------------------------------ -------- ------------ ARTICLEID NOT NULL NUMBER(20) USERKEY NUMBER(10) AVIEWORIGIN_REFID VARCHAR2(10) SUCCESS_IND VARCHAR2(2) ENTRY_CREATEDDATE DATE CREATED_BY VARCHAR2(10) FILENUMBER NUMBER(10) LINENUMBER NUMBER(10) ACCTNUM VARCHAR2(10) AUTOCOMPLETEDTERM NUMBER(2) REQUESTDATETIME VARCHAR2(19)
Published by: Chaitanya on June 9, 2011 02:44SQL> select * from table(dbms_xplan.display); PLAN_TABLE_OUTPUT ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ Plan hash value: 2224314832 ---------------------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop | ---------------------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 590 | 33040 | 2501K (1)| 08:20:15 | | | | 1 | HASH GROUP BY | | 590 | 33040 | 2501K (1)| 08:20:15 | | | | 2 | PARTITION RANGE ALL| | 590 | 33040 | 2501K (1)| 08:20:15 | 1 |1048575| |* 3 | TABLE ACCESS FULL | TABLE1 | 590 | 33040 | 2501K (1)| 08:20:15 | 1 |1048575| ---------------------------------------------------------------------------------------------------------- PLAN_TABLE_OUTPUT ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ Predicate Information (identified by operation id): --------------------------------------------------- 3 - filter(UPPER("OS"."SUCCESS_IND")='S' AND CASE WHEN ('FULL'='FULL' AND "OS"."ENTRY_CREATEDDATE">=TO_DATE(' 2011-04-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND "OS"."ENTRY_CREATEDDATE"<=TO_DATE(' 2011-06-07 00:00:00', 'syyyy-mm-dd hh24:mi:ss')) THEN 1 WHEN 'FULL'='INCR' THEN 1 END =1 AND "OS"."REQUESTDATETIME" IS NOT NULL AND CASE WHEN ('FULL'='FULL' AND "ODS"."GET_DATE_TIMESTAMP"("REQUESTDATETIME")>=TO_DATE(' 2011-05-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND "ODS"."GET_DATE_TIMESTAMP"("REQUESTDATETIME")<=TO_DATE(' 2011-05-31 00:00:00', 'syyyy-mm-dd hh24:mi:ss')) THEN 1 WHEN ('FULL'='INCR' AND "OS"."ENTRY_CREATEDDATE">=TO_DATE(' 2011-05-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND "OS"."ENTRY_CREATEDDATE"<=TO_DATE(' PLAN_TABLE_OUTPUT ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 2011-05-31 00:00:00', 'syyyy-mm-dd hh24:mi:ss')) THEN 1 END =1 AND "OS"."ACCTNUM" IS NOT NULL AND "OS"."AVIEWORIGIN_REFID" IS NOT NULL)
Published by: Chaitanya on June 9, 2011 02:47When it is executed individually, MERGE LOGIC 1 and LOGIC of MERGE 2 take about ten for a daterange of 30 days data.
BUT FULL is to get the scores of APR - JUN, INCR becomes partitions for MAY so not both 30 days.
Are compare us like with like? -
Using a CASE statement in 'IN' where clause clause
Hello
I have a form that users see after they connect with a few items and they type or select values based on the element type. All reports in the application use these values of PAGE 1 in where clause to filter the lines.
One of these question is "Quarter". I have a group of radio buttons on the PAGE 1 on the P1_QTR point.
I need to provide users a way to take the last 4, last 3, last 2 or current quarter and I need to dynamically build a clause WHERE the interactive report based on the selection in the form.
I am trying to use the CASE as shown below and get the syntax error.
AND QTR to (when BOX: P1_QTR = 'CURRENT' then ("T4"))
When: P1_QTR = "LAST" then ("Q3")
When: P1_QTR = 'LAST TWO' then ('Q3, "Q4")
When: P1_QTR = 'LAST THREE' then ("Q2", "Q3,' T4 ')
another ("T1", "T2", "Q3,' T4 ')
END)
How can I achieve this?
Following a simple logic, try
and QTR to
(
Select 'T4' double where: P1_QTR <> 'LAST '.
Union of all the
Select 'Q3' to double where: P1_QTR <> "in PROCESS".
Union of all the
Select "Q2" double where: P1_QTR not in ('CURRENT', 'LAST', "LAST TWO")
Union of all the
Select "Q1" double where: P1_QTR not in ('CURRENT', 'LAST', 'LAST TWO', 'THREE LATEST')
)
-
How to set a null column in a where clause clause involving a statement box
In oracle APEX, I a (selection list) element called: P32_STATUS. It contains two values of interest (for this discussion): 'Available' and 'checked '. In my report, I have a column called vc_status that contains two values: "Checkbox" and NULL. In my application I want to use a case statement in my where clause similar to the lines of
where
.
.
.
AND (vc_status = CASE WHEN: P32_STATUS = "Checkbox" THEN : P32_STATUS )
WHEN : P32_STATUS = 'Available' THEN NULL END)
The 'box' filtering works but the filtering to try to vc_status the NULL value does not work. Can someone help me? Thank you!
(P.S. My intuition says that there because I can not put vc_status = NULL, but I must say that vc_status IS NULL... However, I don't know how to do execution IS ZERO inside a CASE statement)
Hello
Your intuition is right...
In Oracle NULL is a bit special:
NULL = NULL is false
NULL <> NULL is false
Thus, instead of the parameter a NULL value in the CASE WHERE there is just set a value on the other side:
NVL (vc_statut, 'Available') =: P32_STATUS
That's all! Simple, clean and functional
Maybe you are looking for
-
How and where can I find my Macbook Pro using the model number
How and where can I find my Macbook Pro "using the MODEL number" NOT the serial NUMBER please... Hello world: I would like to know more about my MacbookPro using model # is if there is a website or a program that I can type my model # so she'll tell
-
Get annoying action ads at the top of the Yahoo home page. I always use Firefox and haven't changed the settings, then why the big announcements? I know that they are put there by Yahoo, but they were not there before and they aren't there when I ope
-
Replacing hard drive on Satellite M105-S1021
Hello I'm looking to replace the hard drive of my laptop M105-S1021. Unfortunately, the disk hard original died on me packed and is about 6 months ago. I was quoted a couple grand to recover "perhaps" the content (no, I didn't have a backup and Yes,
-
When I click on Add / Remove programs in the Control Panel, the window is empty.
When I go to access control panel "Add or Remove Programs", it goes to the right screen, but remains empty, I was never able tro access it and my computer needs to be cleaned by removing the stuff that I haven't used for a long time. Can someone plea
-
Can MapPoint 2011 - be installed without the substitution of previous versions?
I need to be able to keep older versions of MapPoint on my laptop while having access to 2011. I could install 2009 without the substitution of 2004 and 2006, but my IT people say it cannot be done with 2011. Can he?