If statement in the SELECT???
I use Coldfusion as my source for remoting with Flash. I have
created different databases for different materials. However when
an order is placed I get the "id" of the material. I also return
the "type" of material. If I would have planned this correctly I
would have just put all the materials in one database and returned
what I needed just fine. As it turns out I cannot change it.
Below is my code and basically what I'd like to do is say
that:
if bag_traits.trait_type = 1
select materials.material_name where bag_orders.bag_trait_a =
materials.material_id
So right now it's returning a 6. I need the name of the
material from the materials database with an id of 6. I also have a
ribbons table where if the trait_type = 2 then I would need the
ribbons.ribbon_name where bag_orders.bag_trait_a =
ribbons.ribbon_id.
How to I make an if or case statement that will pull the name
from the appropriate database depending on the trait_type? Thanks!
C-Rock wrote:
>
> Why can I not use the material_id number in more than
one column for the
> bag_orders table?
>
As far as I know, that is not the proper way to join multiple
tables.
To join multiple tables you use multiple joins.
I.E.
FROM tableA INNER JOIN tableB ON tableA.key = tableB.key
INNER JOIN
tableC ON tableA.key = tableC.key INNER JOIN tableD ON
tableC.key =
tableD.key
Each join between to tables creates another 'relation'
(database speak
for table like object_ that you can then join to another
table to create
a new relaion and so on and so on. For complex queries it is
usually
much easier to start with the first to tables, confirm that
you return
the desire results, then add the next table. Keep adding one
table at a
time confirming you are getting the expected results each
iteration
before adding another.
Similar Messages
-
How can I use an IF statement in the SELECT
Hi People,
I have a procedure called ENQUEUE_PROC which takes 3 parameters.
and I am trying to use an if statement in the select. I appreciate the help with this task.
here is my code.
Please have a look at my Select statement. What I have does not compile, however it might give you an idea of what i need.
PROCEDURE ENQUEUE_PROC(P_SUBMISSION_ID NUMBER,
P_EVENT VARCHAR2,
CASE_TYPE_CODE NUMBER;
) AS
XMLDATA XMLTYPE;
enqueue_options dbms_aq.enqueue_options_t;
message_properties dbms_aq.message_properties_t;
message_handle RAW(16);
message SYS.AQ$_JMS_TEXT_MESSAGE;
BEGIN
SELECT
XMLELEMENT("caseFileEvent", XMLATTRIBUTES('http://www.ussc.gov/soa/casefile/event/types' AS "xmlns",
'http://www.ussc.gov/soa/casefile/event/types' AS "xmlns:ns0"),
XMLELEMENT("caseFileUploadEvent", XMLATTRIBUTES('http://www.w3.org/2001/XMLSchema-instance' AS "xmlns:xsi",
'http://www.ussc.gov/soa/casefile/event/types ../xsd/Case_META.xsd' AS "xsi:schemaLocation",
'http://www.ussc.gov/soa/casefile/event/types' AS "xmlns"),
XMLELEMENT("taskEvent", P_EVENT), --eg - 'SUBMIT', 'REJECT', 'RESUBMIT'
XMLELEMENT("defendentDetails",
XMLELEMENT("sentensingDate", SMD.SENT_VIO_DATE),
XMLELEMENT("personDetails",
// Here is where I want my IF statement, *********************************
IF CASE_TYPE_CODE = 10 THEN
XMLELEMENT("personNameDetails",
XMLELEMENT("firstName", SMD.FIRST_NAME),
XMLELEMENT("middleName", SMD.MIDDLE_NAME),
XMLELEMENT("lastName", SMD.LAST_NAME)
), -- personNameDetails
ELSE
XMLELEMENT("personNameDetails",
XMLELEMENT("corpname", SMD.CORPNAME),
), -- personNameDetails
XMLELEMENT("dateOfBirth", SMD.BIRTH_DATE)
) -- personDetails
), -- defendentDetails
XMLELEMENT("documentStatusDetails",
XMLELEMENT("otherStatus",
XMLELEMENT("intCode", NULL),
XMLELEMENT("description", NULL)
) -- otherStatus
), -- documentStatusDetails
XMLELEMENT("uploadOtherDetails",
XMLELEMENT("submissionId", SUB.SUBMISSION_ID),
XMLELEMENT("submissionSessionId", SUB.SUB_SESSION_ID),
XMLELEMENT("submissionMethod",
XMLELEMENT("intCode", SUB.SUB_MTHD_CODE),
XMLELEMENT("description", SM.DESCRIP)
), -- submissionMethod
XMLELEMENT("submissionReason",
XMLELEMENT("intCode", SUB.SUB_TYPE_CODE),
XMLELEMENT("description", SR.DESCRIP)
), -- submissionReason
XMLELEMENT("district",
XMLELEMENT("intCode", SMD.DIST_ID),
XMLELEMENT("description", D.DISTRICT_NAME)
), -- district
XMLELEMENT("caseFileType",
XMLELEMENT("intCode", SUB.CASE_TYPE_CODE),
XMLELEMENT("description", C.DESCRIP)
), -- caseFileType
XMLELEMENT("primaryDocketInfo",
XMLELEMENT("yearYY", SUBSTR(SMD.DOCKET, 1, 2)),
XMLELEMENT("id", SUBSTR(SMD.DOCKET, 3, 7)),
XMLELEMENT("defendentNumber", SMD.DEF_NUM)
), -- primaryDocketInfo
XMLELEMENT("PACTSId", SMD.PACTS_ID), -- PACTSId
XMLELEMENT("AOJudgeId",
XMLELEMENT("intCode", SMD.AO_JUDGE_ID),
XMLELEMENT("description", J.LAST_NAME || ', ' || J.FIRST_NAME || ', ' || J.MIDDLE_NAME)
), -- AOJudgeId
XMLELEMENT("missingCasefile", SUB.MISSING_CASE), -- missingCasefile
XMLELEMENT("creator",
XMLELEMENT("firstName", NULL),
XMLELEMENT("lastName", NULL),
XMLELEMENT("email", SUB.CREATOR_ID),
XMLELEMENT("actionDate", REGEXP_REPLACE( TO_CHAR(SUB.CREATE_TIME, 'YYYY-MM-DD"T"HH24:MI:SS.FFTZR'), '...(......)$', '\1'))
), -- creator
XMLELEMENT("lastModifier",
XMLELEMENT("firstName", NULL),
XMLELEMENT("lastName", NULL),
XMLELEMENT("email", H.USER_ID),
XMLELEMENT("actionDate", TO_CHAR(H.ACTION_DATE, 'YYYY-MM-DD"T"HH24:MI:SS".000-05:00"'))
) -- lastModifier
) -- uploadOtherDetails
) -- caseFileUploadEvent
) -- caseFileEvent
INTO XMLDATA
FROM USSC_CASES.SUBMISSION SUB,
USSC_CASES.SUBMISSION_METADATA SMD,
USSC_CASES.CASE_HISTORY H,
LOOKUP.CASE_SUB_MTHD SM,
LOOKUP.CASE_SUB_TYPE SR,
LOOKUP.DISTRICTS D,
LOOKUP.JUDGES J,
LOOKUP.CASE_TYPES C
WHERE SUB.SUBMISSION_ID = SMD.SUBMISSION_ID
AND SUB.SUBMISSION_ID = H.SUBMISSION_ID
AND SUB.SUB_MTHD_CODE = SM.SUBMTHD_CODE
AND SUB.SUB_TYPE_CODE = SR.SUBTYPE_CODE
AND SUB.CASE_TYPE_CODE = C.CASE_TYPE_CODE
AND SMD.DIST_ID = D.USSC_DISTRICT_ID
AND SMD.AO_JUDGE_ID = J.AO_JUDGE_ID
AND H.ACTION_DATE IN (SELECT MAX(A.ACTION_DATE)
FROM USSC_CASES.CASE_HISTORY A
WHERE A.SUBMISSION_ID = P_SUBMISSION_ID)
AND SUB.SUBMISSION_ID = P_SUBMISSION_ID;
--dbms_output.put_line('queue start '|| xmldata.getclobval());
--insert into test1 values(xmldata);
message := SYS.AQ$_JMS_TEXT_MESSAGE.construct;
message.set_text(xmldata.getStringVal());
DBMS_AQ.ENQUEUE(queue_name => 'case_file_queue', -- aqadm.cases_queue
enqueue_options => enqueue_options,
message_properties => message_properties,
payload => message,
msgid => message_handle);
COMMIT;
END ENQUEUE_PROC;thanks for the help,
I believe I almost got it to compilw, however I am getting Error(29,19): PL/SQL: ORA-00918: column ambiguously defined.
Of course CASE_TYPE_CODE is ambiguously because its passed in, is there a way around this.
Here is what i have so far.
PROCEDURE ENQUEUE_PROC(P_SUBMISSION_ID NUMBER,
P_EVENT VARCHAR2,
CASE_TYPE_CODE NUMBER // passed in field
) AS
XMLDATA XMLTYPE;
enqueue_options dbms_aq.enqueue_options_t;
message_properties dbms_aq.message_properties_t;
message_handle RAW(16);
message SYS.AQ$_JMS_TEXT_MESSAGE;
BEGIN
SELECT
XMLELEMENT("caseFileEvent", XMLATTRIBUTES('http://www.ussc.gov/soa/casefile/event/types' AS "xmlns",
'http://www.ussc.gov/soa/casefile/event/types' AS "xmlns:ns0"),
XMLELEMENT("caseFileUploadEvent", XMLATTRIBUTES('http://www.w3.org/2001/XMLSchema-instance' AS "xmlns:xsi",
'http://www.ussc.gov/soa/casefile/event/types ../xsd/Case_META.xsd' AS "xsi:schemaLocation",
'http://www.ussc.gov/soa/casefile/event/types' AS "xmlns"),
XMLELEMENT("taskEvent", P_EVENT), --eg - 'SUBMIT', 'REJECT', 'RESUBMIT'
XMLELEMENT("defendentDetails",
XMLELEMENT("sentensingDate", SMD.SENT_VIO_DATE),
CASE
WHEN CASE_TYPE_CODE = 10 THEN
XMLELEMENT("personDetails",
XMLELEMENT("personNameDetails",
XMLELEMENT("firstName", SMD.FIRST_NAME),
XMLELEMENT("middleName", SMD.MIDDLE_NAME),
XMLELEMENT("lastName", SMD.LAST_NAME)
), -- personNameDetails
XMLELEMENT("dateOfBirth", SMD.BIRTH_DATE)
) -- personDetails
ELSE
XMLELEMENT("corporationDetails",
XMLELEMENT("organizationName", SMD.CORP_NAME)
) -- corporationDetails
END
), -- defendentDetails
XMLELEMENT("documentStatusDetails",
XMLELEMENT("otherStatus",
XMLELEMENT("intCode", NULL),
XMLELEMENT("description", NULL)
) -- otherStatus
), -- documentStatusDetails
XMLELEMENT("uploadOtherDetails",
XMLELEMENT("submissionId", SUB.SUBMISSION_ID),
XMLELEMENT("submissionSessionId", SUB.SUB_SESSION_ID),
XMLELEMENT("submissionMethod",
XMLELEMENT("intCode", SUB.SUB_MTHD_CODE),
XMLELEMENT("description", SM.DESCRIP)
), -- submissionMethod
XMLELEMENT("submissionReason",
XMLELEMENT("intCode", SUB.SUB_TYPE_CODE),
XMLELEMENT("description", SR.DESCRIP)
), -- submissionReason
XMLELEMENT("district",
XMLELEMENT("intCode", SMD.DIST_ID),
XMLELEMENT("description", D.DISTRICT_NAME)
), -- district
XMLELEMENT("caseFileType",
XMLELEMENT("intCode", SUB.CASE_TYPE_CODE),
XMLELEMENT("description", C.DESCRIP)
), -- caseFileType
XMLELEMENT("primaryDocketInfo",
XMLELEMENT("yearYY", SUBSTR(SMD.DOCKET, 1, 2)),
XMLELEMENT("id", SUBSTR(SMD.DOCKET, 3, 7)),
XMLELEMENT("defendentNumber", SMD.DEF_NUM)
), -- primaryDocketInfo
XMLELEMENT("PACTSId", SMD.PACTS_ID), -- PACTSId
XMLELEMENT("AOJudgeId",
XMLELEMENT("intCode", SMD.AO_JUDGE_ID),
XMLELEMENT("description", J.LAST_NAME || ', ' || J.FIRST_NAME || ', ' || J.MIDDLE_NAME)
), -- AOJudgeId
XMLELEMENT("missingCasefile", SUB.MISSING_CASE), -- missingCasefile
XMLELEMENT("creator",
XMLELEMENT("firstName", NULL),
XMLELEMENT("lastName", NULL),
XMLELEMENT("email", SUB.CREATOR_ID),
XMLELEMENT("actionDate", REGEXP_REPLACE( TO_CHAR(SUB.CREATE_TIME, 'YYYY-MM-DD"T"HH24:MI:SS.FFTZR'), '...(......)$', '\1'))
), -- creator
XMLELEMENT("lastModifier",
XMLELEMENT("firstName", NULL),
XMLELEMENT("lastName", NULL),
XMLELEMENT("email", H.USER_ID),
XMLELEMENT("actionDate", TO_CHAR(H.ACTION_DATE, 'YYYY-MM-DD"T"HH24:MI:SS".000-05:00"'))
) -- lastModifier
) -- uploadOtherDetails
) -- caseFileUploadEvent
) -- caseFileEvent
INTO XMLDATA
FROM USSC_CASES.SUBMISSION SUB,
USSC_CASES.SUBMISSION_METADATA SMD,
USSC_CASES.CASE_HISTORY H,
LOOKUP.CASE_SUB_MTHD SM,
LOOKUP.CASE_SUB_TYPE SR,
LOOKUP.DISTRICTS D,
LOOKUP.JUDGES J,
LOOKUP.CASE_TYPES C
WHERE SUB.SUBMISSION_ID = SMD.SUBMISSION_ID
AND SUB.SUBMISSION_ID = H.SUBMISSION_ID
AND SUB.SUB_MTHD_CODE = SM.SUBMTHD_CODE
AND SUB.SUB_TYPE_CODE = SR.SUBTYPE_CODE
AND SUB.CASE_TYPE_CODE = C.CASE_TYPE_CODE
AND SMD.DIST_ID = D.USSC_DISTRICT_ID
AND SMD.AO_JUDGE_ID = J.AO_JUDGE_ID
AND H.ACTION_DATE IN (SELECT MAX(A.ACTION_DATE)
FROM USSC_CASES.CASE_HISTORY A
WHERE A.SUBMISSION_ID = P_SUBMISSION_ID)
AND SUB.SUBMISSION_ID = P_SUBMISSION_ID;
--dbms_output.put_line('queue start '|| xmldata.getclobval());
--insert into test1 values(xmldata);
message := SYS.AQ$_JMS_TEXT_MESSAGE.construct;
message.set_text(xmldata.getStringVal());
DBMS_AQ.ENQUEUE(queue_name => 'case_file_queue', -- aqadm.cases_queue
enqueue_options => enqueue_options,
message_properties => message_properties,
payload => message,
msgid => message_handle);
COMMIT;
END ENQUEUE_PROC;Edited by: Rooney on Jan 31, 2012 1:55 PM -
Using case when statement in the select query to create physical table
Hello,
I have a requirement where in I have to execute a case when statement with a session variable while creating a physical table using a select query. let me explain with an example.
I have a physical table based on a select table with one column.
SELECT 'VALUEOF(NQ_SESSION.NAME_PARAMETER)' AS NAME_PARAMETER FROM DUAL. Let me call this table as the NAME_PARAMETER table.
I also have a customer table.
In my dashboard that has two pages, Page 1 contains a table with the customer table with column navigation to my second dashboard page.
In my second dashboard page I created a dashboard report based on NAME_PARAMETER table and a prompt based on customer table that sets the NAME_ PARAMETER request variable.
EXECUTION
When i click on a particular customer, the prompt sets the variable NAME_PARAMETER and the NAME_PARAMETER table shows the appropriate customer.
everything works as expected. YE!!
Now i created another table called NAME_PARAMETER1 with a little modification to the earlier table. the query is as follows.
SELECT CASE WHEN 'VALUEOF(NQ_SESSION.NAME_PARAMETER)'='Customer 1' THEN 'TEST_MART1' ELSE TEST_MART2' END AS NAME_PARAMETER
FROM DUAL
Now I pull in this table into the second dashboard page along with the NAME_PARAMETER table report.
surprisingly, NAME_PARAMETER table report executes as is, but the other report based on the NAME_PARAMETER1 table fails with the following error.
Error Codes: OPR4ONWY:U9IM8TAC:OI2DL65P
State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 16001] ODBC error state: S1000 code: 1756 message: [Oracle][ODBC][Ora]ORA-01756: quoted string not properly terminated. [nQSError: 16014] SQL statement preparation failed. (HY000)
SQL Issued: SET VARIABLE NAME_PARAMETER='Novartis';SELECT NAME_PARAMETER.NAME_PARAMETER saw_0 FROM POC_ONE_DOT_TWO ORDER BY saw_0
If anyone has any explanation to this error and how we can achieve the same, please help.
Thanks.Hello,
Updates :) sorry.. the error was a stupid one.. I resolved and I got stuck at my next step.
I am creating a physical table using a select query. But I am trying to obtain the name of the table dynamically.
Here is what I am trying to do. the select query of the physical table is as follows.
SELECT CUSTOMER_ID AS CUSTOMER_ID, CUSTOMER_NAME AS CUSTOMER_NAME FROM 'VALUEOF(NQ_SESSION.SCHEMA_NAME)'.CUSTOMER.
The idea behind this is to obtain the data from the same table from different schemas dynamically based on what a session variable. Please let me know if there is a way to achieve this, if not please let me know if this can be achieved in any other method in OBIEE.
Thanks. -
Case sensitive statement in the select-statement
Hi All,
i have a table in the abap-dictionary filled with names...when i try to select them with the select-statement with condition:
table-name_column like 'some_name'
I have encountered some problems...the inquiry is case-sensitive. What i want to do is to read the value from the abap-dictionary table uppercase or lowercase and compare it with the needed value also translated in uppercase or lowercase.
The only idea i have is to select all values of the dictionary table into an internal table and to translate the values there in uppercase or lowercase and then to loop trough it. But this approach would cost a lot of performance.
Do someone has an other proposal?check...
Select statement
It would be difficult , because it is based on how data is stored in the data base , now consider the scenario of the system i am using , we can material description as 'test' or 'TEST' , 'Test' .
If in your system there are only stored in either caps or small the you can perform the select twice .
But i myself dont find it to be such a good solution , but you can give it a try
There is one more solution specific to material description ,and that is in the table MAKT there is a field MAKTG , which stored the description in uppercase , so for this you can first convert the description to uppercase and then perform select on this field -
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. -
How to use read statement on a select options
Hi all,
I am trying to read the all the values on user selection screen select options.
I have an internal table loaded with data.
So while looping this internal table, I need to check the table certain tank field (lgort) against the select options tank values entered by user.
It is fine when user uses the multiple values on the select options since I use the "READ" statement on the select options and get the matching values.
Example: when user uses the multiple value selection on a select-options to enter values A554 and A555
The select-options table will be:
sign option low high
I EQ A554
I EQ A555
LOOP AT gt_output_location INTO gw_output.
READ TABLE s_lgort INTO gw_lgort WITH KEY low = gw_output-lgort.
IF sy-subrc = 0.
* append row to another table.
ENDIF.
ENDLOOP.
Problem:
Example: when user uses range on a select-options to enter values A554 and A555
sign option low high
I BT A554 A555
The read statement can only get matching value A554.
LOOP AT gt_output_location INTO gw_output.
READ TABLE s_lgort INTO gw_lgort WITH KEY low = gw_output-lgort.
IF sy-subrc = 0.
* append row to another table.
ENDIF.
ENDLOOP.
Anyone have any idea on this?? Thanks!!Hi all, I need to consider each and every lines of the gt_output_location as there are other fields need to consider also. Basically I am checking each and every lines of this table to see which lines I need to append to another table.
That is why I did not use "LOOP AT gt_output_location INTO gw_output WHERE lgort IN s_lgort"
The full gt_output_location:
LOOP AT gt_output_location INTO gw_output.
* IF p_lgort = space AND p_umlgo = space.
IF gv_lines_lgort = 0 AND gv_lines_umlgo = 0.
* only append those from tank <> to tank
IF gw_output-lgort <> gw_output-umlgo.
APPEND gw_output to gt_output.
CLEAR gw_output.
ELSE. "from tank == to tank
* append those from plant <> to plant
IF gw_output-werks <> gw_output-umwrk.
APPEND gw_output to gt_output.
CLEAR gw_output.
ENDIF.
ENDIF.
* ELSEIF p_lgort = space AND p_umlgo <> space.
ELSEIF gv_lines_lgort = 0 AND gv_lines_umlgo > 0.
* IF gw_output-umlgo = p_umlgo.
READ TABLE s_umlgo INTO gw_umlgo WITH KEY low = gw_output-umlgo.
IF sy-subrc = 0.
* only append those from tank <> to tank
IF gw_output-lgort <> gw_output-umlgo.
APPEND gw_output to gt_output.
CLEAR gw_output.
ELSE. "from tank == to tank
* append those from plant <> to plant
IF gw_output-werks <> gw_output-umwrk.
APPEND gw_output to gt_output.
CLEAR gw_output.
ENDIF.
ENDIF.
ENDIF.
* ELSEIF p_umlgo = space AND p_lgort <> space.
ELSEIF gv_lines_umlgo = 0 AND gv_lines_lgort > 0.
* IF gw_output-lgort = p_lgort.
READ TABLE s_lgort INTO gw_lgort WITH KEY low = gw_output-lgort.
IF sy-subrc = 0.
* only append those from tank <> to tank
IF gw_output-lgort <> gw_output-umlgo.
APPEND gw_output to gt_output.
CLEAR gw_output.
ELSE. "from tank == to tank
* append those from plant <> to plant
IF gw_output-werks <> gw_output-umwrk.
APPEND gw_output to gt_output.
CLEAR gw_output.
ENDIF.
ENDIF.
ENDIF.
ELSE.
* IF gw_output-lgort = p_lgort AND gw_output-umlgo = p_umlgo.
READ TABLE s_lgort INTO gw_lgort WITH KEY low = gw_output-lgort.
IF sy-subrc = 0.
* only append those from tank <> to tank
IF gw_output-lgort <> gw_output-umlgo.
APPEND gw_output to gt_output.
CLEAR gw_output.
ELSE. "from tank == to tank
* append those from plant <> to plant
IF gw_output-werks <> gw_output-umwrk.
APPEND gw_output to gt_output.
CLEAR gw_output.
ENDIF.
ENDIF.
ENDIF.
READ TABLE s_umlgo INTO gw_umlgo WITH KEY low = gw_output-umlgo.
IF sy-subrc = 0.
* only append those from tank <> to tank
IF gw_output-lgort <> gw_output-umlgo.
APPEND gw_output to gt_output.
CLEAR gw_output.
ELSE. "from tank == to tank
* append those from plant <> to plant
IF gw_output-werks <> gw_output-umwrk.
APPEND gw_output to gt_output.
CLEAR gw_output.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
CLEAR gw_lgort.
CLEAR gw_umlgo.
ENDLOOP. -
If I want to order by dateAdded to I have to include it in the select statement like
If I do this:
<cfquery name="chart" datasource="#datasource#">
select behaviourID,score, dateAdded2 = convert(varchar,
dateAdded , 101)
from staff_charts_data
where userID =
<cfqueryparam value="#arguments.userID#"
cfsqltype="cf_sql_integer"> AND
NOT score = 5
</cfquery>
If I want to order by dateAdded to I have to include it in
the select statement like so:
<cfquery name="chart" datasource="#datasource#">
select behaviourID,score, dateAdded2 = convert(varchar,
dateAdded , 101),dateAdded
from staff_charts_data
where userID =
<cfqueryparam value="#arguments.userID#"
cfsqltype="cf_sql_integer"> AND
NOT score = 5
</cfquery>you should be able to order by dateAdded without it being in
the select clause. The only time the order by field has to be in
the select clause is when your query has an aggregate and group by
clause, like this:
select field1, field2, max(field3) as youralias
from sometables
where whatever
group by field1, field2
order by ???
You can only order field1, field2, max(field3) or youralias.
You can't order by field4. -
Issue with Past Month data in the Select Statement
Hi,
I written the following query,
SELECT /*+NO_MERGE(A)*/
CASE
WHEN snap_shot_date > a.q3
AND snap_shot_date <= a.q4
THEN q4char
WHEN snap_shot_date > a.q2 AND snap_shot_date <= a.q3
THEN q3char
WHEN snap_shot_date > a.q1 AND snap_shot_date <= a.q2
THEN q2char
WHEN snap_shot_date > a.q0 AND snap_shot_date <= a.q1
THEN q1char
END snap_shot_date,
CASE
WHEN snap_shot_date > a.q3 AND snap_shot_date <= a.q4
THEN 1
WHEN snap_shot_date > a.q2 AND snap_shot_date <= a.q3
THEN 2
WHEN snap_shot_date > a.q1 AND snap_shot_date <= a.q2
THEN 3
WHEN snap_shot_date > a.q0 AND snap_shot_date <= a.q1
THEN 4
END sort_by,
pillar3_exposure_class_code, pd_band_description,
ROUND (SUM (p3.ead_post_sec_post_crm)),
ROUND (SUM (notional_principle)),
DECODE (SUM (notional_principle),
0, 0,
ROUND ( SUM (DECODE (exposure_type,
'UNDRAW', ead_post_sec_post_crm,
0
/ SUM (notional_principle),
4
DECODE (SUM (p3.ead_post_sec_post_crm),
0, 0,
ROUND ( SUM (pd_value * p3.ead_post_sec_post_crm)
/ SUM (p3.ead_post_sec_post_crm),
2
DECODE (SUM (p3.ead_post_sec_post_crm),
0, 0,
ROUND (SUM (rwa) / SUM (p3.ead_post_sec_post_crm), 4)
DECODE (SUM (p3.ead_post_sec_post_crm),
0, 0,
ROUND ( SUM (lgd_rate * p3.ead_post_sec_post_crm)
/ SUM (p3.ead_post_sec_post_crm),
2
TO_CHAR (MAX (a.max_date), 'FMMonth DD, YYYY')
FROM summary.pillar3 p3,
(SELECT DISTINCT (month_end_date) max_date,
LAST_DAY (month_end_date) q4,
TO_CHAR (LAST_DAY (month_end_date),
'MON YYYY'
) q4char,
ADD_MONTHS (LAST_DAY (month_end_date), -3) q3,
TO_CHAR
(ADD_MONTHS (LAST_DAY (month_end_date), -3),
'MON YYYY'
) q3char,
ADD_MONTHS (LAST_DAY (month_end_date), -6) q2,
TO_CHAR
(ADD_MONTHS (LAST_DAY (month_end_date), -6),
'MON YYYY'
) q2char,
ADD_MONTHS (LAST_DAY (month_end_date), -9) q1,
TO_CHAR
(ADD_MONTHS (LAST_DAY (month_end_date), -9),
'MON YYYY'
) q1char,
ADD_MONTHS (LAST_DAY (month_end_date), -12) q0
FROM rcdwstg.stg_bcar_detail) a
WHERE snap_shot_date BETWEEN ADD_MONTHS (a.max_date, -12) AND a.max_date
GROUP BY CASE
WHEN snap_shot_date > a.q3 AND snap_shot_date <= a.q4
THEN q4char
WHEN snap_shot_date > a.q2 AND snap_shot_date <= a.q3
THEN q3char
WHEN snap_shot_date > a.q1 AND snap_shot_date <= a.q2
THEN q2char
WHEN snap_shot_date > a.q0 AND snap_shot_date <= a.q1
THEN q1char
END,
CASE
WHEN snap_shot_date > a.q3 AND snap_shot_date <= a.q4
THEN 1
WHEN snap_shot_date > a.q2 AND snap_shot_date <= a.q3
THEN 2
WHEN snap_shot_date > a.q1 AND snap_shot_date <= a.q2
THEN 3
WHEN snap_shot_date > a.q0 AND snap_shot_date <= a.q1
THEN 4
END,
pillar3_exposure_class_code,
pd_band_description
ORDER BY 2 DESC;I have written the query to get the latest 12 months data from a table and split that into 4 quarter to show in the Cognos Report. But when the table having 13th or the past months data, the select statement is showing Empty values in the first two columns and fetching the 13 month data too.
Can anyone help me in this to avoid the problem.
Thanks
Radha KWHERE snap_shot_date BETWEEN ADD_MONTHS(TRUNC(a.max_date, 'MM'), -11) AND a.max_date
.... -
How can I call a Page Process from the Select statement for Report Page
I'm able to call a javascript using the below:
img src="#IMAGE_PREFIX#add2.gif" border="0" alt="Icon 4" onClick="javascript:add_connect1('||CPORT.ID||')"
But Now,
I'd like to accomplish (2) New things:
1. instead of using,....... onClick="javascript:add_connect1,
I'd like to call a Page Process, onClick=
2. I'd like to be able to call two different processes onClick.
a. onClick="javascript:passBack('||ID||')"
b. onClick= <Please see my question #1 above>
Can someone please help me with the syntax for this,
If indeed it can even be done?
Thanks- GaryGreg.
It seems that my situation is the one you describe in you second paragraph, where you mention:
you could then add the ID column value as a parameter to the javascript functionBut,
I do not know how to reference the variable in my javascript nor how to use it in my on-demand process.
If you can hellp me past this last little bump, then I think I will be able to use these skills in Sooo many different areas of my design.
Here's what I've got so far:
A. In the select statement I identify the javascript as:
onClick="javascript:connect_port('<font color=blue>''||ID||''</font>')";
B. In my javascript I have this:
<script language="JavaScript" type="text/javascript">
function connect_port(ID)
var get = new htmldb_Get(null,$x('pFlowId').value,'APPLICATION_PROCESS=CONNECT_PORT',0);
gReturn = get.get();
get = null;
</script>
C. In my on demand function I have this:
BEGIN
INSERT INTO CCONNECTIONS_B
BLDG_ID,CLST_ID,PORT_ID,STRAND_ID
) VALUES
:P2004_BLDG_ID,:P2004_CLST_ID,:P2004_PORT_ID,:P2004_STRAND_ID1
END;
You can see that I dont know how to use the value for 'ID' in either the javascript or the On-Process function.
If you can help me out with this one, Then I can imitate it for the rest.
-Gary
Edited by: garyNboston on Apr 3, 2009 6:44 AM
Edited by: garyNboston on Apr 3, 2009 6:44 AM
Edited by: garyNboston on Apr 3, 2009 6:45 AM
Edited by: garyNboston on Apr 3, 2009 6:47 AM -
How to use a table name in the select statement using a variable?
Hi Everybody,
I got a internal table which has a field or a variable that gets me some tables names. Now I need to retrieve the data from all these tables in that field dynamically at runtime. So could you suggest me a way out to use the select query which uses this variable as a table ?
Regards,
Mallik.Hi all,
Actually i need some more clarification. How to use the same select statement, if i've to use the tabname in the where clause too?
for ex : select * from (tab_name) where....?
Can we do inner join on such select statements? If so how?
Thanks & Regards,
Mallik. -
How to pass the parameter in the where clause of the select statement
Hi All,
Iam getting one of the value from the Input otd and using this value i need to query one of the tables in oracle database and selected the table using the oracle eway otd like shown below .
otdRISKBLOCK_1.getRISKBLOCK().select() .
where clause in side the select takes a string parameter as Iam getting the string parameter from the input otd and passing this to where clause by creating a string literal after deployment it is giving an error saying "ORA-00920: invalid relational operator".
can any one throw some input on this .
Thanks in Advance
SrikanthYou will see this error if the search condition was entered with an invalid or missing relational operator.
You need to include a valid relational operator such as
=, !=, ^=, <>, >, <, >=, <=, ALL, ANY, [NOT] BETWEEN, EXISTS, [NOT] IN, IS [NOT] NULL, or [NOT] LIKE in the condition. in the sql statement.
Can you throw some more light on how are you designing your project? -
* table name in the select statements
Hi,
I have come across a select Statement as below.
Select * into *nast from nast where <conditions>.. End select.
what does this *nast represents and when is it used. why do we need to call a Table with *<Table Name>
Kind Regards,
Ushahi,
select statement will always points to a database table so we have to give database table name and it gets data from that table. for storing that data we have to use internal tables must have same structure of database table.
so select statement has the following form as........
select * from [dbtable] into table [internal table]
endselect.
in sap select will act as a loop so that we hav to use end sleect. select has different varities in sap. for some types no need of end select.
for ex:
select single *
select * ..................... into table [internal table name].....
if helpful reward some points.
with regards,
suresh. -
Using Select Statement in the decoe function in Oralce Form10 g
Hello All:
Is it possible to call another Select Statement inside the Decode Function in Oracle Form? I tested the SQL on PL/SQL Plus, it ran without giving any errors. However, I got the following errors when I tried to compile the procedure in the Oracle Form right after the where condiction at the first select statement....
Error 103 at line number....
Encountered the symbol "," when expecting one of the following
) intersect minus order union .....
Select a.col1
a.col2,
decode((select min(test_date) pa_closr_date from table_name c where a.col1 = c.col1), null, a.col3,(select min(test_date) pa_closr_date from table_name c where a.col1 = c.col1)) test_date,
a.col4,
from table_name a;
thanks ahead for any help.
KMDYou don't need the Select within the decode. In SQL Plus, I tried your SQL using this:
Select
a.col1,
a.col2,
decode( (select min(test_date) pa_closr_date
from table_name c where a.col1 = c.col1), null, a.col3,
(select min(test_date) pa_closr_date
from table_name c where a.col1 = c.col1)
) test_date
from table_name a;And this gives the same result:
Select
a.col1,
a.col2,
decode(c.pa_closr_date, null, a.col3, c.pa_closr_date ) test_date
from table_name a,
( select col1, min(test_date) pa_closr_date
from table_name
group by col1 ) c
where c.col1(+) = a.col1; -
Re: Select statement in the report
Hi Experts,
In my selection-screen contains ernam as a parameter.
If it balnk in the selection-screen,
the select statement is not working.
if it is not blank ,the select statement is working fine.
TABLES: vbak.
TYPES: BEGIN OF ty_vbak,
vbeln TYPE vbeln,
knumv TYPE knumv,
END OF ty_vbak.
DATA: v_vkorg TYPE vkorg,
v_vtweg TYPE vtweg,
v_erdat TYPE erdat.
DATA: i_vbak TYPE STANDARD TABLE OF ty_vbak.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS: p_ernam TYPE ernam .
SELECT-OPTIONS: s_vkorg FOR v_vkorg,
s_vtweg FOR v_vtweg,
s_erdat FOR v_erdat.
PARAMETERS: p_kvgr4 TYPE tvv4-kvgr4 OBLIGATORY.
SELECTION-SCREEN END OF BLOCK b1.
START-OF-SELECTION.
SELECT vbeln
knumv
FROM vbak
INTO TABLE i_vbak
WHERE erdat IN s_erdat
AND ernam = p_ernam
AND vkorg IN s_vkorg
AND vtweg IN s_vtweg
AND kvgr4 = p_kvgr4.
IF sy-subrc = 0.
WRITE:/ 'HI'.
ENDIF.
Thank's in Advance,
Harsha.report .
TABLES: vbak.
TYPES: BEGIN OF ty_vbak,
vbeln TYPE vbeln,
knumv TYPE knumv,
END OF ty_vbak.
DATA: v_vkorg TYPE vkorg,
v_vtweg TYPE vtweg,
v_erdat TYPE erdat.
DATA: i_vbak TYPE STANDARD TABLE OF ty_vbak with header line.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
select-options: s_ernam for vbak-ernam .
SELECT-OPTIONS: s_vkorg FOR v_vkorg,
s_vtweg FOR v_vtweg,
s_erdat FOR v_erdat.
PARAMETERS: p_kvgr4 TYPE tvv4-kvgr4 .
SELECTION-SCREEN END OF BLOCK b1.
START-OF-SELECTION.
SELECT vbeln
knumv
FROM vbak
INTO TABLE i_vbak
WHERE erdat IN s_erdat
AND ernam in s_ernam
AND vkorg IN s_vkorg
AND vtweg IN s_vtweg
AND kvgr4 = p_kvgr4.
IF sy-subrc = 0.
loop at i_vbak.
write:/ i_vbak-vbeln.
endloop.
ENDIF. -
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,
Maybe you are looking for
-
Missing Generating Bursting Status Report
Hi, EBS R12. I got log for XML Publisher Report Bursting Program, But after the Start bursting process.. I didn't get Generating Bursting Status Report. May somebode familiar with this problem ? Thank you, MRERP2
-
Ipod nano is not recognised on my mac
I have a Mac and an ipod and a nano and have previously sync both -no problem. Now the nano is not recognised by the mac. it show 'do not disconnect' and charges ok but doesn't appear on the source list so i can't restore or sync. I've tried resettin
-
My messages cannot be delivered
ERROR ..... This message could not be delivered and will remain in your Outbox until it can be delivered. The SMTP server "smtp.my server.net" doesn't support authentication. Please check your account setting and try again....... I have been fighting
-
HP Laserjet 1102 Keeps goin offline
Hi There - our hp laseret 1102 printer keeps going offline. It happens completely randomly, sometimes it might not happen for days other times it happens every day. I have checked the usb settings in device manager and there is no option to put the
-
I Phone generates huge amount of traffic on its own
Hi there, I have a serious Problem with one of my IPhones. It started to generate about 2GB of Traffic within a short period of time without me doing anything. All apps closed. It exceede my included traffic and now the provider claims about 1500 EUR