CASE statement in a join condition
Hello
I'm stuck in this part of the code, where I use CASES in a join condition. I work in Teradata, so I can't use "DECODE".
LEFT JOIN V610413. TEAM_ASSIGNMENTS your
-C.firm_id = your. FirmId
ONE BOX WHEN your. FirmId = c.firm_id THEN your. FirmId = c.firm_id
WHEN your. FirmId <>c.firm_id THEN your. FirmId = 'no value '.
END
AND c.stateId = ta.stateId
Please advice
LEFT JOIN V610413. TEAM_ASSIGNMENTS your
We'RE your. FirmId = CASE WHEN your. FirmId = c.firm_id THEN c.firm_id
WHEN your. FirmId <> c.firm_id THEN 'no value '.
END
AND c.stateId = ta.stateId
Tags: Database
Similar Questions
-
Join the results of a case statement
Hello everyone;
I can't with a query where I use a case statement to create a new column and attempt to reach an additional table on the resulting column. I am fairly new to this and learn by trial and error, so if you think that it looks a little ugly or ineffective, I won't be offended. It is used on my interface based on the web of companies, while I am not able to answer some basic questions such as the version of db.
My need to use the case statement is the result of some strange methods and somewhat contradictory in order to link the product subcodes (sku, fcsku, fnsku), to a product code parent (ProdID). In this case, the inventory is stored in the first table with one of the few types of premises SKUs, however the dimensional data only links to the ProdID. I'm trying to instruction box allows to send the parent a second table (ProdID) code if the sku is there, or a third table if it is found on this table. The main reason (in this case) I have to this ProdID is I can join the dimensional data of a fourth table.
My current query:
SELECT / * + USE_HASH (dbin, sku, xProdID, msr) * /.
dbin.snapshot_date, dbin.bin_id, dbin. ISBN,
CASE WHEN sku. ProdID IS NULL THEN xProdID.ITEM_AUTHORITY_ID
Of ANOTHER sku. ProdID
END ProdIDMaster,
dbin. OWNER, dbin. QUANTITY, dbin. CONTAINER_ID,
MSR. HEIGHT, msr. WIDTH, msr. LENGTH, msr. WEIGHT, msr. DIMENSIONAL_UOM, msr. WEIGHT_UOM,
MSR. HEIGHT * msr. WIDTH * msr. LENGTH as a Volume
OF D_BIN_ITEMS dbin
SKU of LEFT JOIN O_FCSKUS ON dbin. ISBN = sku. FCSKU
LEFT JOIN (SELECT * FROM D_FNSKU_ProdID_MAP)
WHERE REGION_ID = 1
AND SNAPSHOT_DAY = TO_DATE('{RUN_DATE_YYYY/MM/DD}','YYYY/MM/DD')) xProdID
ON dbin. ISBN = xProdID.FULFILLMENT_NETWORK_SKU
LEFT JOIN (SELECT * FROM D_MP_ProdID_PKG_MEASUREMENTS)
WHERE REGION_ID = 1 AND MARKETPLACE_ID = 1 AND PACKAGE_TYPE_ID = 1) msr
ON ProdIDMaster = msr. ProdID
WHERE dbin. WAREHOUSE_ID = "PHL5."
AND dbin. Snapshot_date = TO_DATE('{RUN_DATE_YYYY/MM/DD}','YYYY/MM/DD')
AND dbin.bin_id like '% P-1-R '.
ORDER BY dbin.bin_id;
The error I receive:
Statement 1 is invalid. ORA-00904: "ProdIDMaster": invalid identifier
ProdIDMaster appears only in two places, an alias for the case statement, as well as a side of the join statement. If I simply change the alias name, it has no effect, so I can only assume the question is how I refer to results of the case statement. I also tried to reach the word 'CASE', which returned "1 statement is not valid. "ORA-00904:"The MATTER": invalid identifier.
Any help or advice would be greatly appreciated.
Post edited by: 8ea4344e-80ea-44e7-b8ac-d482be7245a7 I made a mistake when I posted the code. The ProdID_ID shown in the join should have been ProdIDMaster. I need to change this due to the fact that the name of the column used (which is what I based my alias on) may have been considered confidential information. All the other columns names remained unchanged.
Hello
8ea4344e-80EA-44e7-B8AC-d482be7245a7 wrote:
Hello everyone;
I can't with a query where I use a case statement to create a new column and attempt to reach an additional table on the resulting column. I am fairly new to this and learn by trial and error, so if you think that it looks a little ugly or ineffective, I won't be offended. It is used on my interface based on the web of companies, while I am not able to answer some basic questions such as the version of db.
My need to use the case statement is the result of some strange methods and somewhat contradictory in order to link the product subcodes (sku, fcsku, fnsku), to a product code parent (ProdID). In this case, the inventory is stored in the first table with one of the few types of premises SKUs, however the dimensional data only links to the ProdID. I'm trying to instruction box allows to send the parent a second table (ProdID) code if the sku is there, or a third table if it is found on this table. The main reason (in this case) I have to this ProdID is I can join the dimensional data of a fourth table.
My current query:
SELECT / * + USE_HASH (dbin, sku, xProdID, msr) * /.
dbin.snapshot_date, dbin.bin_id, dbin. ISBN,
CASE WHEN sku. ProdID IS NULL THEN xProdID.ITEM_AUTHORITY_ID
Of ANOTHER sku. ProdID
END ProdIDMaster,
dbin. OWNER, dbin. QUANTITY, dbin. CONTAINER_ID,
MSR. HEIGHT, msr. WIDTH, msr. LENGTH, msr. WEIGHT, msr. DIMENSIONAL_UOM, msr. WEIGHT_UOM,
MSR. HEIGHT * msr. WIDTH * msr. LENGTH as a Volume
OF D_BIN_ITEMS dbin
SKU of LEFT JOIN O_FCSKUS ON dbin. ISBN = sku. FCSKU
LEFT JOIN (SELECT * FROM D_FNSKU_ProdID_MAP)
WHERE REGION_ID = 1
AND SNAPSHOT_DAY = TO_DATE('{RUN_DATE_YYYY/MM/DD}','YYYY/MM/DD')) xProdID
ON dbin. ISBN = xProdID.FULFILLMENT_NETWORK_SKU
LEFT JOIN (SELECT * FROM D_MP_ProdID_PKG_MEASUREMENTS)
WHERE REGION_ID = 1 AND MARKETPLACE_ID = 1 AND PACKAGE_TYPE_ID = 1) msr
ON ProdIDid_ID = msr. ProdID
WHERE dbin. WAREHOUSE_ID = "PHL5."
AND dbin. Snapshot_date = TO_DATE('{RUN_DATE_YYYY/MM/DD}','YYYY/MM/DD')
AND dbin.bin_id like '% P-1-R '.
ORDER BY dbin.bin_id;
The error I receive:
Statement 1 is invalid. ORA-00904: "ProdIDMaster": invalid identifier
ProdIDMaster appears only in two places, an alias for the case statement, as well as a side of the join statement. If I simply change the alias name, it has no effect, so I can only assume the question is how I refer to results of the case statement. I also tried to reach the word 'CASE', which returned "1 statement is not valid. "ORA-00904:"The MATTER": invalid identifier.
Any help or advice would be greatly appreciated.
Whenever you have a problem, please post a small example data (CREATE TABLE and only relevant columns, INSERT statements) of all the tables involved, so that people who want to help you can recreate the problem and test their ideas.
Also post the exact results you want from this data, as well as an explanation of how you get these results from these data, with specific examples.
Always say what version of Oracle you are using (for example, 11.2.0.2.0). Use "SELECT * VERSION of $ v;" to get it.
See the FAQ forum: Re: 2. How can I ask a question on the forums?
When you define an alias for column (such as PriodIDMaster) in the SELECT a query clause, you can use the alias in the ORDER byclause in this request, but this is the only place in this same query, where you can use it. If you want to use anywhere, like in a join condition, then calculate the new column in a subquery; then you can use it anywhere you want in a Super request.
I see expression BOX (not the same as a declarationBOX) where when ProdIDMaster is defined, but I do not see where it is used. Are you sure that you posted the code that is causing the problem?
-
I wonder if it's possible to put conditional case statements in a subquery in a pl sql view?
I have a sub request, and final statement is:
is it possible to do something like this conditionally includes the statement "AND"?AND EXISTS (SELECT NULL FROM steps ps WHERE ps.route = pr.id AND ps.step_type= 1
WHEN id = 1( AND EXISTS (SELECT NULL FROM steps ps WHERE ps.route = pr.id AND ps.step_type= 1)
When there is more conditions, better put everything in extra parentheses (because of the condition of GOLD):
...
AND (id != 1 OR (id = 1 AND EXISTS (SELECT NULL FROM steps ps WHERE ps.route = pr.id AND ps.step_type= 1))) -
Case statement to certain conditions
Hello guys
I'm wondering may us, follow these steps
Suppose that I have given gross
and should be out putId Date status 1 9/1 s 2 9/1 s 3 9/1 s 4 9/1 e 5 9/1 e 6 9/2 e 7 9/2 s
I am trying to use the Case statement, but do not get the resultToday(9/2) Yesd(9/1) Status count(id) 1 3 s count(id) 1 2 e
Help, please
Thank youHello
A column alias, like week, can be used in the ORDER BY clause of the query, where it was defined.
This is the only place where it can be used in the same query. in particular, do not use it in the GROUP BY clause.Or the other
(1) repeat the expression in the GROUP BY clause, or
(2) calculate the value in a subquery:Either
(1) repeat the expression in the GROUP BY clause
SELECT Case When (TRUNC (Load_Date) - trunc(to_date(substr(Status_date,1,19),'YYYY/MM/DD HH24:MI:SS'))) Between 2 and 7 Then '2-7 d' Else 'rest' End As week ,Count(id) FROM Report where Trunc(Load_Date) Between Trunc(sysdate -59) and Trunc(Sysdate - 53) and job_type not like 'Check' GROUP BY Case When (TRUNC (Load_Date) - trunc(to_date(substr(Status_date,1,19),'YYYY/MM/DD HH24:MI:SS'))) Between 2 and 7 Then '2-7 d' Else 'rest' End ;
or
(2) to calculate the value in a subquery
WITH got_week AS ( SELECT Case When (TRUNC (Load_Date) - trunc(to_date(substr(Status_date,1,19),'YYYY/MM/DD HH24:MI:SS'))) Between 2 and 7 Then '2-7 d' Else 'rest' End As week , id FROM Report where Trunc(Load_Date) Between Trunc(sysdate -59) and Trunc(Sysdate - 53) and job_type not like 'Check' ) SELECT week , COUNT (id) AS cnt FROM got_week GROUP BY week ;
Efficiency and do as much as possible in the subquery of filtering.
Speaking of efficiency:
where Trunc (Load_Date) Between Trunc (sysdate - 59) and Trunc (Sysdate - 53)
has the same effect as
WHERE Load_Date >= TRUNC (SYSDATE - 59) AND Load_Date < TRUNC (SYSDATE - 52)
but the second way is more effective. It uses one less operation TRUNC, but more importantly, it allows the optimizer to use an index on Load_Date.
-
Case statement with a select &; date in
Hello everyone,
This is my first discussion, so please bare with me.
I am trying to write a case statement with a select statement that compares the dates.
When I write an instruction box with a select statement in it compares everything but dates it works fine. Once the date is there, he collapses.
Here is a super simple example of what I'm trying to do, "b.in_serv_dt" is a date
Select unit_no,
case when ((sélectionnez b.in_serv_dt de b unit_dept_comp_main où a.unit_id = b.unit_id et b.in_serv_dt) > = 1 January 2012 "") then "everybody wins."
When ((sélectionnez b.in_serv_dt dans l'unit_dept_comp_main b où a.unit_id = b.unit_id et b.in_serv_dt) < = 1 January 2012 "") then "Nobody wins".
end
of ottawa_unitmain_v one
Any help would be greatly appreciated
Thank you very much
Hello
your statement of formatting:
Select unit_no
case when ((select b.in_serv_dt
of unit_dept_comp_main b
where a.unit_id = b.unit_id
and b.in_serv_dt
") > = JANUARY 1, 2012"
) and then "everybody wins."
When ((select b.in_serv_dt
of unit_dept_comp_main b
where a.unit_id = b.unit_id
and b.in_serv_dt
)<=>=>
) and then "no winner".
end
of ottawa_unitmain_v oneI see "partial conditions": <... and="" b.in_serv_dt="">> that have no meaning.
I guess it's a kind of "typo" and I ignore them.
If the statement is:
Select unit_no
case when ((select b.in_serv_dt
of unit_dept_comp_main b
where a.unit_id = b.unit_id
") > = JANUARY 1, 2012"
) and then "everybody wins."
When ((select b.in_serv_dt
of unit_dept_comp_main b
where a.unit_id = b.unit_id
)<=>=>
) and then "no winner".
end
of ottawa_unitmain_v oneI guess that the "b select" retrieve one line, through the design of database (forced...)
As already written: be careful with data types: avoid "implicit conversions" (when you compare different data types, Oracle has convert the data type of the other side, a side example: "mystring = mynumber" is transformed into 'TO_NUMBER (mystring) = mynumber', or 'mydate = mystring' translates mydate = TO_DATE (mystring,
) ")
Even better: use explicit conversions, use explicit formats when necessary.
Best: use no conversion on columns from the constants, but use the correct data type for the constant.With this in mind:
Select unit_no
case when ((select b.in_serv_dt
of unit_dept_comp_main b
where a.unit_id = b.unit_id
) > DATE = ' 2012-01-01'
) and then "everybody wins."
When ((select b.in_serv_dt
of unit_dept_comp_main b
where a.unit_id = b.unit_id
)<= date="">=>
) and then "no winner".
end
of ottawa_unitmain_v one
But note that b.in_serv_dt EQUAL to 1 January 2012 (at 00:00:00) is OK for both WHEN the conditions; then the a "win."Now: the subselect statement is identical in the 2 options of the case... You could work differently: (I add the "ELSE" in case one line as NULL in_serv_dt;) I guess that an INNER JOIN is OK, maybe you need a LEFT OUTER JOIN (if some lines of A have no corresponding row in B)
SELECT a.unit_no
, CASE WHEN b.in_serv_dt > = DATE '' 2012-01-01
THEN "everyone wins"
WHEN b.in_serv_dt< date="">
While "Nobody wins".
ELSE ' who knows... ". »
END who_wins
Of ottawa_unitmain_v one
INNER JOIN unit_dept_comp_main b
ON a.unit_id = b.unit_id
;Best regards
Bruno Vroman
-
Hello
I am trying to use a global variable 'Global.test' in my ODI "pkg_test" package and step declaration type as a variable that is defined with the value 1 when my package evaluates the condition successfully run and with 0 if the fails.now condition I will carry out the same "pkg_test" package in my load "LP_TEST" and using the variable 'Global.test' Plan as a case statement in terms of load "LP_TEST".
It's workload Odi is unable to understand the value of the variable 'Global.test', which is defined in my pkg 'pkg_test' and my case statement is put down in my care Plan.
Thank you
Hi Santosh Pradhan,
What kind of story do you have in your variable?
If you have not selected any antecedent, the scope of the variable is limited to the session. As the execution of the package is a session in its own (independent of the workload performance), the value of the variable is not accessible after his execution.
You can also try assigning / updating of the value of the variable directly from your plan, instead of in the package:
It will be useful.
Best regards
JeromeFr
-
Syntax of the case statement / WHEN
The table I use a depreciation per fiscal year and the fiscal period. I try to have the amount of depreciation to go to 2 different columns based on the fiscal year and the fiscal year. I'm doing it with a nested case statement. I know that is not correct, because I get the message ORA-00905. I'm relatively new to sql and it is contribtuing to my problem as well. Here is the code I have and suggestions / corrections would be appreciated. Thanks for the help...
SELECT
lao PDR. DEPTID as DEPTID,
lao PDR. ASSET_ID as ASSET_NO,
PA. Descr as DESCRIPTION,
lao PDR. ACCOUNT_AD as AD_ACCT,
PDL. DE_ACCT, to take into ACCOUNT
lao PDR. ADEATH as AMT_DEPR,
PDL. JOURNAL_ID as JRNL_ID,
PDL. JOURNAL_DATE as JRNL_DT,
lao PDR. FISCAL_YEAR as FY,
lao PDR. ACCOUNTING_PERIOD AP,
CASE
WHEN RDP. FISCAL_YEAR = 2014 THEN
WHEN RDP. PERIOD ACCOUNTANT = 11 THEN pdr. DEPR
END AS CURR_MONTH,
CASE
WHEN RDP. FISCAL_YEAR <>2014
WHEN RDP. ACCOUNTING PERIOD <>11 THEN pdr. DEPR
END AS PRIOR_MONTH
OF PS_DEPR_RPT pdr
INNER JOIN PS_DIST_LN pdl
THE pdl. BOOK = pdr. BOOK
AND pdl. BUSINESS_UNIT = pdr. BUSINESS_UNIT
AND pdl. FISCAL_YEAR = pdr. FISCAL_YEAR
AND pdl. ACCOUNTING_PERIOD = pdr. ACCOUNTING_PERIOD
AND pdl. ASSET_ID = pdr. ASSET_ID
AND pdl. CF_SEQNO = pdr. CF_SEQNO
INNER JOIN PS_ASSET PA
WE pa. ASSET_ID = pdl. ASSET_ID
AND pa. BUSINESS_UNIT = pdl. BUSINESS_UNIT
WHERE
lao PDR. BUSINESS_UNIT = "A0465.
AND pdr. BOOK = 'RUN '.
AND ((pdr. FISCAL_YEAR = 2014 AND pdr. ACCOUNTING_PERIOD = 11) OR (pdr. FISCAL_YEAR = 2014 AND pdr. ACCOUNTING_PERIOD = 10))
Hello
2713822 wrote:
Thank you... I appreciate the information you provide when you answer these questions. I always try to get the amount (from the same column) for 2 rows in different columns. I tried the LAST_VALUE and LAG but it took a long time for the queries to run, I'm looking for another way to do the same. I'm only using SQL to retrieve data. I don't have the ability to create or insert.
I looked the information above and the CASE statement to look like this:
CASE
WHEN RDP. FISCAL_YEAR = 2014
AND pdr. ACCOUNTING_PERIOD = 11
THEN the RDP. ADEATH AS CURR_MONTH
ON THE OTHER
lao PDR. ADEATH AS MONTHS PREVIOUS
END
But I'm now getting an "ORA-00905: lack of keyword" message.
What I'm trying to do is to draw 2 lines 1 to 2014 / 11 and another for 2014 / 10. The amount for the period 2014 / 11 should go in the current column and the amount for the period 2014 / 10 should go in the previous column.
Before current assets management
01 AB01 50.01 50.03
....
If you want to give an alias for a column, then you can say "AS nome_alias" after that tell you what that is in this column.
'AS nome_alias' applies to the entire column. Cannot use 'alias_name' in the middle of an expression, for example, in the middle of a CASE expression, before the END keyword.
If you want to have 2 separate output columns, curr_month and prior_month to your output, you must then 2 separate columns in your SELECT clause. for example:
SELECT pdr.branch
pdr.asset
CASE
WHEN pdr.fiscal_year = 2014
AND pdr.accounting_period = 11
THEN pdr.depr
END AS curr_month
CASE
WHEN...
THEN...
END AS prior_month
PDR
;
If post you some sample data (CREATE TABLE and INSERT statements), the results and explanations, I could show you how to complete the... sections.
To find out what version of Oracle you have, use
SELECT *.
SINCE the release of v$.
The output can be messy, like this:
BANNER
-------------------------------------------------------------------
CON_ID
----------
12 c Oracle database Release 12.1.0.1.0 - 64 bit Production
0
PL/SQL Release 12.1.0.1.0 - Production
0
CORE Production 12.1.0.1.0
0
AMT for 64-bit Windows: Version 12.1.0.1.0 - Production
0
NLSRTL Version 12.1.0.1.0 - Production
0
The important thing is the number 5 parts on the first line; 12.1.0.1.0 in the example above.
-
Case statement in the SQL Query prompt dashboard
Hi Experts,
I use the following case statement to generate default values in the prompt dashboard based on a condition (the other guest-generated values). Below are two of the query I've tried and the syntax error. I tried all the possibilities (like giving apostrophes, double quotes, don't quote not etc.), but could not understand the question. Don't know what exactly I'm missing here.
Query 1:
SELECT
CASE
WHEN @{PRType} = monthly THEN 'Participant pay '. "" Amount of PayRate "="15000"
WHEN @{PRType} = daily THEN 'Participant pay '. "" Amount of PayRate "="650"
WHEN @{PRType} = hourly THEN 'Participant pay '. "" Amount of PayRate "="1"
ELSE ' 0'
END
OF 'PA-Participant pay. '
Query 2:
SELECT
CASE
WHEN @{PRType} = monthly THEN "15000"
WHEN @{PRType} = daily THEN "650"
@{PRType} = schedule THEN '1'
ELSE ' 0'
END
OF 'PA-Participant pay. '
This is the query that is generated in the log with error message file.
1 log message:
SELECT CASE WHEN Hourly = Monthly THEN "Participant Payroll"."Payrate Amount" = '15000' WHEN Hourly = Daily THEN "Participant Payroll"."Payrate Amount" = '650' WHEN Hourly = Hourly THEN "Participant Payroll"."Payrate Amount" = '1' ELSE '0' END FROM "PA-Participant Payroll"
State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error occurred. [nQSError: 43113] The message returned by OBIS. [nQSError: 27002] Near <>=: Syntax error [nQSError: 26012]. (HY000)
Comment 2:
;CASE WHEN To_Char (Hourly) = 'Hourly' THEN 1 ELSE 0 END
State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error occurred. [nQSError: 43113] The message returned by OBIS. [nQSError: 27002] Near <>(): syntax error [nQSError: 26012]. (HY000)
Sorry, I wasn't clear... you must always put this CASE statement in a valid SQL SELECT statement.
SELECT
CASE
When ' @{PRType}' = 'Monthly' THEN '15000'
When ' @{PRType}' = 'Daily' THEN '650'
ELSE '0' END
OF 'PA-Participant pay. '
-
Select with case statement and a formula of the IIR
Hi, I was looking to get help regarding a statement writing box with a statement select statement all. I tried to reproduce a formula IIf access well that just wanted to check that the query I wrote is correct, any advice would be appreciated.
[code]
Select *.
Of
(
Select name, month, duration, volume, time_spent, date1, date2,.
-case when 'date' > = 'date1' then '1' other '0' end as departure,.
-case when 'date' < = "date2" then '1' other '0' as end ending
Of
(
Select *.
of call_1 cd
inner join call_2 ON cd.name = cl.queue cl
)
)
;
[/ code]
I want to know is where I have my ' select name, etc, I would change that to select * to make it easier instead of typing all the field_names outside, but I don't know how to do and also what follows is 2 IIF formulas from an access database for the start of the final case statements so I just wanted check I wrote it correctly.
[code]
departure: IIf ([date] > = [date1], 1, 0)
[/ code]
[code]
ending: IIf ([date] < = [date2], 1, 0)
[/ code]
Any advice would be appreciated.
Hello
Whenever you have any questions, post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and the results desired from these data.
Explain, using specific examples, how you get these results from these data.If the output depends on what anyone outside the application itself (for example, when it is run) and then include a few different examples and the results you want of each given the same sample data. For example, "if I run on November 19, 2013, while the results should be... because... but if I run between November 21 and November 27, then the results should be... because...". »
Always say what version of Oracle you are using (for example, 11.2.0.2.0).See the FAQ forum: https://forums.oracle.com/message/9362002
318f20b8-a3d0-4FB4-bb0f-73785250b7d4 wrote:
Hi, I was looking to get help regarding a statement writing box with a statement select statement all. I tried to reproduce a formula IIf access well that just wanted to check that the query I wrote is correct, any advice would be appreciated.
[code]
Select *.
Of
(
Select name, month, duration, volume, time_spent, date1, date2,.
-case when 'date' > = 'date1' then '1' other '0' end as departure,.
-case when "date."<= 'date2'="" then="" '1'="" else="" '0'="" end="" as="">=>
Of
(
Select *.
of call_1 cd
inner join call_2 ON cd.name = cl.queue cl
)
)
;
[/ code]
I want to know is where I have my ' select name, etc, I would change that to select * to make it easier instead of typing all the field_names outside, but I don't know how to do and also what follows is 2 IIF formulas from an access database for the start of the final case statements so I just wanted check I wrote it correctly.
[code]
departure: IIf([date]>=[date1],1,0)
[/ code]
[code]
ending: IIf ([date]<>
[/ code]
Any advice would be appreciated.
DATE is not a function of Oracle; in fact, it's a terrible name for a column or function, because it blends with the DATE data type.
In Oracle, the function SYSDATE returns the date and time, according to the clock on the database server. So, SYSDATE can return a value as November 19, 2013 06:33:15. If you want to midnight the same day (i.e., November 19, 2013 00:00:00) and then use TRUNC (SYSDATE).
String literals (for example the string which consists 5 characters d, a, t, e, and 1) go inside the single quotes. Numbers and the names of columns only.
If you want to include all the columns, more some calculated values, in a SELECT clause, then you must use a name table or alias before the *. (See select_2 below. To do this, assign the alias j to display online.)
Maybe you wanted to say something like:
Select *-it's select_1
de)
Select j. *-it's select_2
, case when SYSDATE > = date1 then 1 or 0 end as departure
, case when SYSDATE<= date2="" then="" 1="" else="" 0="" end="" as="">=>
de)
Select *-it's select_3
of call_1 cd
inner join call_2 ON cd.name = cl.queue cl
) j
)
;
As mentioned in a previous answer, you should be careful about the use of "SELECT *" in production code.
In select_3, it would be better if you explicitly listed the columns you need. It can improve efficiency and maintenance. In this request, queue and the name will be always the same, so you probably don't want to include both of them in the result set, in any case.
In select_1 and select_2, it is acceptable to use "SELECT *", assuming that select_3 is fixed.
Moreover, there is no point in using subqueries here. You can get the same results simply in a single query, without any subqueries.
-
Hello everyone. I'm having a hell of a time trying to understand my nested case statement. It's pretty simple, but I always feel to get this error:
ORA-00937: not a single group group function
* 00937. 00000 - 'not a single-group function. "
Cause:
Action:
However, when I try to enter in a "group by" I get this error:
ORA-00979: not a GROUP BY expression
* 00979. 00000 - 'not a GROUP BY expression. "
Cause:
Action:
I don't know if there is something wrong with my nested case statement syntax, or miss me something more fundamental. This is my code:
I appreciate all help. Nice day.SELECT AE.EMP_ID, CASE WHEN EP.PHYSICAL_DATE IS NULL THEN CASE WHEN EC.ORIGINAL_CONTRACT_START < ((SYSDATE) - 365) THEN 'NEEDS PHYSICAL' WHEN EC.ORIGINAL_CONTRACT_START < ((SYSDATE) - 330) THEN 'COMING UP' ELSE 'No' END WHEN MAX(EP.PHYSICAL_DATE) KEEP (DENSE_RANK LAST ORDER BY EP.PHYSICAL_DATE) < ((SYSDATE) - 365) THEN 'NEEDS PHYSICAL' WHEN MAX(EP.PHYSICAL_DATE) KEEP (DENSE_RANK LAST ORDER BY EP.PHYSICAL_DATE) < ((SYSDATE) - 330) THEN 'COMING UP' ELSE 'No' END "Needs Physical?" FROM AP AE LEFT JOIN EMP_PHYSICAL EP ON AE.EMP_ID = EP.EMP_ID LEFT JOIN POSITION_OFFERED PO ON AE.EMP_ID = PO.EMP_ID LEFT JOIN EMP_CONTRACT EC ON AE.EMP_ID = EC.EMP_ID WHERE PO.ACTUAL_END IS NULL AND (EP.PHYSICAL = 1 OR EP.PHYSICAL IS NULL) AND :P71_EMP_ID = AE.EMP_ID;
AquaSELECT AE.EMP_ID,
CASE
WHEN EP.PHYSICAL_DATE IS NULL
THEN
CASE
WHEN EC.ORIGINAL_CONTRACT_START < ((SYSDATE) - 365)
THEN 'NEEDS PHYSICAL'
WHEN EC.ORIGINAL_CONTRACT_START < ((SYSDATE) - 330)
THEN 'COMING UP'
ELSE 'No'
END
WHEN MAX(EP.PHYSICAL_DATE) KEEP (DENSE_RANK LAST
ORDER BY EP.PHYSICAL_DATE) < ((SYSDATE) - 365)
THEN 'NEEDS PHYSICAL'
WHEN MAX(EP.PHYSICAL_DATE) KEEP (DENSE_RANK LAST
ORDER BY EP.PHYSICAL_DATE) < ((SYSDATE) - 330)
THEN 'COMING UP'
ELSE 'No'
END "Needs Physical?"
FROM AP AE
LEFT JOIN EMP_PHYSICAL EP
ON AE.EMP_ID = EP.EMP_ID
LEFT JOIN POSITION_OFFERED PO
ON AE.EMP_ID = PO.EMP_ID
LEFT JOIN EMP_CONTRACT EC
ON AE.EMP_ID = EC.EMP_ID
WHERE PO.ACTUAL_END IS NULL
AND (EP.PHYSICAL = 1
OR EP.PHYSICAL IS NULL)
AND :P71_EMP_ID = AE.EMP_ID;
GROUP BY AE.EMP_ID,EP.PHYSICAL_DATE,EC.ORIGINAL_CONTRACT_START;Hi,
You need to add Group by clause at the end of the query i have added above.
-
Between the statement/Case statement
Hi all
I can't find how to use the case statement when you try to find pick_date between X and Y.
The following example shows if the day = Monday then use
where pick_date between next_day (trunc (sysdate)-14, 'MY') and next_day (trunc (sysdate)-7, 'SAT')
Otherwise, use
where pick_date between next_day (trunc (sysdate)-7, 'MY') and next_day (trunc (sysdate), 'SAT')
Select apple
of the double
where pick_date between
(case when to_char(sysdate,'d') = 2 then
(next_day (trunc (sysdate)-14, 'MY') and next_day (trunc (sysdate)-7, 'SAT'))
on the other
(next_day (trunc (sysdate)-7, 'MY') and next_day (trunc (sysdate), 'SAT'))
end)
Thanks in advance!the condition is
BETWEEN expr1 AND expr2
so you can easily use
select apple from dual where pick_date between (case when to_char(sysdate,'d') = 2 then next_day(trunc(sysdate)-14,'MON') else next_day(trunc(sysdate)-7,'MON') end) and (case when to_char(sysdate,'d') = 2 then next_day(trunc(sysdate)-7,'SAT') else next_day(trunc(sysdate),'SAT') end);
-
OLAP cube - complex join condition
Hi Experts,
I requires a complex join between the dimension and cube.
Requirement goes like this-
We have a dimension to the date level-
January 1, 2011
January 2, 2011
...
.. and so on.
The fact table is not a matching surrogate key, but it has valid_from_date and valid_to_date that are stamps.
I need to join these two to reach the condition readings - where dim.date between trunc (valid_from_date) and trunc (valid_to_date).
Is it possible/feasible? Enjoyed your responses.
Best regards, MarionYou should be able to set a condition like this in the field "Join Condition" of the mapping pane cube in AWM. You would need to qualify table names to be something like this
dim_table.date between trunc(fact_table.valid_from_date) and trunc(fact_table.valid_to_date).
The only restriction to this approach is that you will not be able to partition on the time dimension for this cube due to the complexity of the condition.
As an alternative, you can define a SQL view that joined your fact table in your time dimension table using the same condition. You map the cube on this point of view, in which case the restriction on partitioning goes.
-
Join condition of cube and other mapping missing mapping
Hi David,
I have a strange problem... After the creation of cube mapping tables defning and physical objects joins and the change of my mapping intermittently disappears... Not being able to trace what's happening. Is this a known bug or nothing is done correctly?
Enjoy your previous answer.
Thank you very much
PaivaA "mapping" is a term of olap product management which means that the cube is not mapped to the level the fact sheet. For example, suppose you have tables like this
CREATE TABLE SALES_FACT ( DAY_OF_SALE DATE, PRODUCT_ID NUMBER, UNITS NUMBER, COST NUMBER ) CREATE TABLE TIME ( DAY DATE, MONTH NUMBER, QUARTER NUMBER, YEAR NUMBER )
Suppose you want to analyze the data only at the level of the MONTH and more. In this case, you must set a time of hierarchy which includes levels MONTHS->->-> ALL_TIME YEAR QUARTER and you would need to define a join condition between SALES_FACT and TIME of the form
SALES_FACT.DAY_OF_SALE = TIME.DAY
This is sometimes called a "mapping" because it maps data in the AW to a higher level than what is stored in the fact (for example, the MONTHS instead of DAYS).
-
NOT IN clause in State of the CASE statement does not
Dear friends,
I want to use on the condition in the WHERE clause of my SELECT statement.
WHERE <>...
<>...
AND eihf.exr_aip_asset_sid NOT IN
(CASE when safa.fund_relation = 'C' and safa.fund_account_code! = vFundAccount)
SO (37874,37909,43424,55040,59513,59598,58570,76148,75885,75927)
ON THE OTHER
(0)
END
)
But it gives me an error like "missing of good parenthis."
Help, please.
Kind regards
JonathanYou can not write a list of values within the case statement.
try something like this,
WHERE <-------------> AND CASE WHEN safa.fund_relation = 'C' AND safa.fund_account_code != vFundAccount THEN eihf.exr_aip_asset_sid ELSE 1 END NOT IN (37874, 37909, 43424, 55040, 59513, 59598, 58570, 76148, 75885, 75927) AND CASE WHEN safa.fund_relation = 'C' AND safa.fund_account_code != vFundAccount THEN 1 ELSE eihf.exr_aip_asset_sid END != 0;
-
Hi all
I am filling a text field based on what the user chooses a drop down which contains the 50 United States of America.
So... Let's say for now I mean 'Birmingham' if the user selects "Alabama", the text field.
The only thing I have at the moment is completely false:
setText() function
{
var statechoice = State.value;
Switch (statechoice) {}
case 1:
Text1.RawValue = "deposit is required in Alabama."
breaking
case 2:
Text1.RawValue = "very cold and the deposit is required in Alaska."
breaking
by default:
Text1.RawValue = "choose a please state";
breaking
}
Must it always be the case 1, 2, 3 and so on? It can never be "case (something is true and something is equal to 7):? I mean, what I always use integers to distinguish the cases?later I want to fill down based on choices that makes the user. I want to have a list of conditional statements where each conditional expresses a unique combination of choice that the user has made.Do you like cold food? YesLactose intolerant? NO.Field of text says "having a cone of ice cream for dessert."How can I get integer values in a drop-down? DropDown.Value? DropDown.index? dropdown.selectedIndex?How to combine these choices in the instructions box? If (dd1 = 1 and 4 = dd2 and dd3 = 2):?Sorry for this discursive question,I just need a good example to follow.Thank you very muchJoeYou can try something like below...
Otherwise, the Switch statement only evaluates to the value that is passed next to the switch control...
var statechoice = State.rawValue;
Switch (statechoice) {}
case "AL":
Text1.RawValue = "deposit is required in Alabama."
Text1.RawValue = Text1.rawValue + setText();
break;
case "AK":
Text1.RawValue = "very cold and the deposit is required in Alaska."
break;
by default:
Text1.RawValue = "choose a please state";
break;
}Added a function inside the same event and call this function in the switch case statements above.
function setText() {}
Switch (otherDropDown.rawValue) {}
case study "Yes":
return "selected Yes;
break;
by default:
Return "No selected ';
break;
}
}I hope this helps...
Thank you
Srini
Maybe you are looking for
-
I submitted a question in "Contributions" and accidentally gave on my e-mail address. How can I remove this question that I submitted?
-
HP DV2700 - Vista using disks fails to make the preinstallation of office software
I'm trying to help my daughter long distance. His laptop crashed and she didn't know why and impossible to restore using disks or F11. She is more concerned about its data and had the drive removed and placed in an external USB enclosure to access it
-
Done IdealPad Z360 (REF 5905 5778) support Windows XP?
Hi, if I understand this idealpad Z360 (REF 5905 5778) arrived with original windows 7, I just want to know is if I downgrade to windows xp, is there a driver for this device?
-
No sound after updating Windows on HP Pavilion g6 8.1
PC updated for Windows 8.1 today and now have no sound at all and the pc says without a helmet or the speakers are plugged and detection detects without problems and also the 'properties' of AMD say sevice work properly (I have no drivers back back t
-
Several call to the method of painting
Ask for help on one of the most common problems in the development of BB UiApp. My method of painting is called more that I can think of logicall. Ask for help to understand why its happening Looks like my request CFL extends ListField implements {Li