Case statement with having null gives default result
Hello,
When we write a case statement with a not equal condition <> on a column and if that columns has null value the it gives the else value.
eg
Select Column_Name, Case when Column_Name <>Condition then 0 else 1 end as case_test from Table_Name.
Ideally null is not equal to the condition so the case should return 0 but it returns 1. Can anyone tell me why?
In addition to the other posts:
NULL is an unknown value, when you say
col <> 1
and col is NULL, we don't know whether col is 1 or something else. Thus the condition evaluates to UNKNOWN. How UNKNOWN is handled depends on the context. In WHEN clauses as well as the IF statments, the effect that the code bracketed by IF/WHEN is not
entered. That is, UNKNOWN and FALSE yields the same result. In CHECK constraints, it's the other way round. If you have
CHECK (WHEN col <> 0)
rows where col is NULL are accepted.
When you work with SQL, no matter the database product, it's imperative to master three-valued logic, because it comes up all the time.
As I said, NULL is the unknown value. In practice, NULL has a distinct interpreation depending on the database column. For instance, NULL in a column called EndDate, usually means that the period (or whatever it is) is still open. So often when you work
with NULL values you use isnull to replace it with some value that fits the context, and finding that value takes some consideration. Blindly doing isnull(col, '') can lead to serious bugs, particularly if col is not a string column.
Erland Sommarskog, SQL Server MVP, [email protected]
Similar Messages
-
Case statement with Subquery
select case when condition then
i want to execute qr1
else qr2
How to implement this ?Hi,
Welcoem to the forum!
972471 wrote:
Case statement with SubqueryHow does a sub-query, or a query, figure in this question?
Be more specific. Post a complete script that you tried, and what output you expected from it. If you got an error, post the complete error message, including line numbers.
See the forum FAQ {message:id=9360002}
select case when condition then
i want to execute qr1
else qr2
How to implement this ?Here's one way:
BEGIN
CASE
WHEN 1 = 1
THEN
dbms_output.put_line ('Condition was TRUE');
ELSE
dbms_output.put_line ('Condition was FALSE or UNKNOWN');
END CASE;
END;
/If the condition involves a query, then you may have to select the results into a variable first, and then use the variable in the CASE statement. -
Help With A Case Statement With Multiple Variables
I apologize if this is the incorrect Forum for this type of question, but it was the closest one that I could find. I'm pretty new with SQL and am stuck on this issue. I have roughly 26 dates that I need to compare to one another. Each date is tied to a step code. I also have a Stop value that is tied directly to the "max date" of the step codes. So, I need to compare 30 dates against one another to 1st - ID the max date; 2nd - ID if the Stop value is correct; 3rd - if the stop value is incorrect, identify what the correct value would be.
At first, this seemed like it wouldn't be that hard. I wrote a query that found the max date for each step code. Then I realized that multiple step codes could have the same date. So, I tried using this case statement, but I did not get the expected results. Is there a more efficient way of getting what I need? This code seems like it's not necessary and probably the source of my issue.
CASE
WHEN FS25.ACTUAL_COMPLETION_DATE > FS.ACTUAL_COMPLETION_DATE AND FS25.ACTUAL_COMPLETION_DATE > FS1.ACTUAL_COMPLETION_DATE AND FS25.ACTUAL_COMPLETION_DATE > FS2.ACTUAL_COMPLETION_DATE AND FS25.ACTUAL_COMPLETION_DATE > FS3.ACTUAL_COMPLETION_DATE AND FS25.ACTUAL_COMPLETION_DATE > FS4.ACTUAL_COMPLETION_DATE AND FS25.ACTUAL_COMPLETION_DATE > FS5.ACTUAL_COMPLETION_DATE AND FS25.ACTUAL_COMPLETION_DATE > FS6.ACTUAL_COMPLETION_DATE AND FS25.ACTUAL_COMPLETION_DATE > FS7.ACTUAL_COMPLETION_DATE AND FS25.ACTUAL_COMPLETION_DATE > FS8.ACTUAL_COMPLETION_DATE AND FS25.ACTUAL_COMPLETION_DATE > FS9.ACTUAL_COMPLETION_DATE AND FS25.ACTUAL_COMPLETION_DATE > FS10.ACTUAL_COMPLETION_DATE AND FS25.ACTUAL_COMPLETION_DATE > FS11.ACTUAL_COMPLETION_DATE AND FS25.ACTUAL_COMPLETION_DATE > FS12.ACTUAL_COMPLETION_DATE AND FS25.ACTUAL_COMPLETION_DATE > FS13.ACTUAL_COMPLETION_DATE AND FS25.ACTUAL_COMPLETION_DATE > FS14.ACTUAL_COMPLETION_DATE AND FS25.ACTUAL_COMPLETION_DATE > FS15.ACTUAL_COMPLETION_DATE AND FS25.ACTUAL_COMPLETION_DATE > FS16.ACTUAL_COMPLETION_DATE AND FS25.ACTUAL_COMPLETION_DATE > FS17.ACTUAL_COMPLETION_DATE AND FS25.ACTUAL_COMPLETION_DATE > FS18.ACTUAL_COMPLETION_DATE AND FS25.ACTUAL_COMPLETION_DATE > FS19.ACTUAL_COMPLETION_DATE AND FS25.ACTUAL_COMPLETION_DATE > FS20.ACTUAL_COMPLETION_DATE AND FS25.ACTUAL_COMPLETION_DATE > FS21.ACTUAL_COMPLETION_DATE AND FS25.ACTUAL_COMPLETION_DATE > FS22.ACTUAL_COMPLETION_DATE AND FS25.ACTUAL_COMPLETION_DATE > FS23.ACTUAL_COMPLETION_DATE AND FS25.ACTUAL_COMPLETION_DATE > FS24.ACTUAL_COMPLETION_DATE AND L.FORECLOSURE_STOP_CODE <= '8' THEN '9'
ELSE 'UH OH'
END AS "CHANGE FC STOP TO"
Any assistance is appreciated!I think Igor pointed out a working solution before.
Applying it at your examples (you missed the operator after STOP_CODE, I assume it =):
CASE
WHEN FS25 = GREATEST(FS25, FS24, FS23) AND STOP_CODE = '9' THEN '9'
ELSE 'UH OH'
END AS 'CHANGE STOP CODE TO'
{code}
Be careful at the second example. You are checking:
{code:sql}
FS25 > FS24 OR FS25 IS NOT NULL AND FS24 IS NULL AND FS25 > FS23
OR
FS25 IS NOT NULL AND FS23 IS NULL AND STOP_CODE = '9'
{code}
Remember that AND has higher priority among operators than OR so if FS25 is greater than FS24 and FS23 the condition will be true even if STOP_CODE is not equal 9.
Regards.
Al -
Case statement with group by clause
SELECT STP, CASE WHEN Alternate IS NULL THEN 3 ELSE 4 END as Ind,
CASE WHEN Alternate IS NULL THEN 'New Address' ELSE 'New Location' END as Description , Count(*) Rec_Cnt
FROM t_Ids
group by STP, CASE WHEN Alternate IS NULL THEN 3 ELSE 4 END, CASE WHEN Alternate IS NULL THEN 'New Address' ELSE 'New Location'
ORDER BY 1,2,3
I need a query something like this. Does anyone has any idea on this???You're missing the END on the GROUP BY Case statement, but otherwise this looks fine.
What problem are you having?
Also, please post DDL
Thanks
Carl -
ITSM Search on status with "is not" gives incorrect results due to SLA statuses
Hi,
When executing a search on Solution Manager ITSM tickets, on the search criterion Status and with operator "is not", the result list does not give correct results.
For example, an incident with status "Confirmed IRT Exceeded" does show up when searching with criterion "Status is not Confirmed".
Is there any solution for this behaviour?
Kind Regards,
JoycaHi Vivek,
Thanks for the Knowledge Article.
The content of the document would indeed help if we only wanted to find "not confirmed" tickets.
However, the same thing is happening on other statuses. For example searching for "status is not proposed solution" is still not possible with the descriptions in the knowledge document, since the user status "proposed solution" is linked to system status "in process" (I1003), like all the other in-between user statuses such as "customer action" and "in process" etc.
The only workaround that I see is to use only "is" as operator and never "is not". However, the underlying problem remains. I think it should be possible to use also "is not" without having issues due to those SLA statuses...
Kr,
Joyca -
CASE statement with MIN?
I am trying to write a case statement which says when STAT is E select the MIN(TERM)
If there is multiple TERM which are both low just pick any. Want one per row per ID.
Is that possible by using case?
Thanks.
CREATE TABLE DAN_GR2
(ID VARCHAR2(12),
TERM VARCHAR2(12),
STAT VARCHAR2(12))
INSERT INTO DAN_GR2 (ID, TERM,STAT) VALUES ('1','5','E')
INSERT INTO DAN_GR2 (ID, TERM,STAT) VALUES ('1','2','D')
INSERT INTO DAN_GR2 (ID, TERM,STAT) VALUES ('1','9','E')
INSERT INTO DAN_GR2 (ID, TERM,STAT) VALUES ('1','5','E')
INSERT INTO DAN_GR2 (ID, TERM,STAT) VALUES ('2','1','E')
INSERT INTO DAN_GR2 (ID, TERM,STAT) VALUES ('2','10','E')
INSERT INTO DAN_GR2 (ID, TERM,STAT) VALUES ('3,'10','D')
ID TERM STAT
1 5 E
1 2 D
1 9 E
1 5 E
2 1 E
2 10 E
3 10 DWant
ID MIN_TERM
1 5
2 1
3 NULLUsing:Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bi
Edited by: Chloe_19 on 12/09/2012 18:07Hi,
So, you don't want to ignore the whole row when stat != 'E' (that would ignore the only row with id='3'). Putting the condition 'stat = 'E' in the WHERE clause sill ignore the row, so that's not what you want.
You just want to ignore the term column. Put the same condition in a CASE expression that only contols that column.
Here's one way:
SELECT id
, MIN ( CASE
WHEN stat = 'E'
THEN term
END
) AS min_e_term
FROM dan_gr2
GROUP BY id
ORDER BY id
; -
Hello,
I am trying to build a query that returns the 3 months of a quarter. Below are the two case statements that I am trying to use. I am getting a "Not a group by expression" in the first case statement, and a "nota a single-group group function in the second. Any help with this would be appreciated.
Thanks, sck10
SELECT Trev.Revenue_Year,
CASE
WHEN Trev.Revenue_Name = 'Jan' THEN Round(SUM(COALESCE(Trev.Revenue, 0)), 1)
WHEN Trev.Revenue_Name = 'Apr' THEN Round(SUM(COALESCE(Trev.Revenue, 0)), 1)
WHEN Trev.Revenue_Name = 'Jul' THEN Round(SUM(COALESCE(Trev.Revenue, 0)), 1)
WHEN Trev.Revenue_Name = 'Oct' THEN Round(SUM(COALESCE(Trev.Revenue, 0)), 1)
ELSE SUM(0)
END AS Month_01,
CASE
WHEN Trev.Revenue_Name = 'Feb' THEN Round(SUM(COALESCE(Trev.Revenue, 0)), 1)
WHEN Trev.Revenue_Name = 'May' THEN Round(SUM(COALESCE(Trev.Revenue, 0)), 1)
WHEN Trev.Revenue_Name = 'Aug' THEN Round(SUM(COALESCE(Trev.Revenue, 0)), 1)
WHEN Trev.Revenue_Name = 'Nov' THEN Round(SUM(COALESCE(Trev.Revenue, 0)), 1)
ELSE SUM(0)
END AS Month_02,
CASE
WHEN Trev.Revenue_Name = 'Mar' THEN Round(SUM(COALESCE(Trev.Revenue, 0)), 1)
WHEN Trev.Revenue_Name = 'Jun' THEN Round(SUM(COALESCE(Trev.Revenue, 0)), 1)
WHEN Trev.Revenue_Name = 'Sep' THEN Round(SUM(COALESCE(Trev.Revenue, 0)), 1)
WHEN Trev.Revenue_Name = 'Dec' THEN Round(SUM(COALESCE(Trev.Revenue, 0)), 1)
ELSE SUM(0)
END AS Month_03
FROM Stage_Report_Revenue Trev
GROUP BY Trev.Revenue_Year;
SELECT Trev.Revenue_Year,
SUM(CASE
WHEN Trev.Revenue_Name = 'Jan' THEN COALESCE(Trev.Revenue, 0)
WHEN Trev.Revenue_Name = 'Apr' THEN COALESCE(Trev.Revenue, 0)
WHEN Trev.Revenue_Name = 'Jul' THEN COALESCE(Trev.Revenue, 0)
WHEN Trev.Revenue_Name = 'Oct' THEN COALESCE(Trev.Revenue, 0)
ELSE 0
END) AS Month_01,
SUM(CASE
WHEN Trev.Revenue_Name = 'Feb' THEN COALESCE(Trev.Revenue, 0)
WHEN Trev.Revenue_Name = 'May' THEN COALESCE(Trev.Revenue, 0)
WHEN Trev.Revenue_Name = 'Aug' THEN COALESCE(Trev.Revenue, 0)
WHEN Trev.Revenue_Name = 'Nov' THEN COALESCE(Trev.Revenue, 0)
ELSE 0
END) AS Month_02,
SUM(CASE
WHEN Trev.Revenue_Name = 'Mar' THEN COALESCE(Trev.Revenue, 0)
WHEN Trev.Revenue_Name = 'Jun' THEN COALESCE(Trev.Revenue, 0)
WHEN Trev.Revenue_Name = 'Sep' THEN COALESCE(Trev.Revenue, 0)
WHEN Trev.Revenue_Name = 'Dec' THEN COALESCE(Trev.Revenue, 0)
ELSE SUM(0)
END) AS Month_03
FROM Stage_Report_Revenue Trev
GROUP BY Trev.Revenue_Year;You are getting the "Not a group by expression" error because you are not using in aggregate functions in your select statement. (You are using the aggregate function SUM in the second query)
The "not a a single-group group function" means you are returning multiple rows of a data when it only expects one.
HTH -
Sql case statement with link not opening new window
Apex 4.2
I am writing a query that has a case statement. I need the case statement to open up a new window, not a new tab. I have the following:
SELECT
case when SCHED_ID = 1 then
'<a href="javascript:popupURL(''http://www.google.com'')">LINK</a>'
end as MyLink
FROM Table_Name
When I plug this into a a column link in the URL field under a page item or report item, then a popup window appears. However, inside the query I am getting a new tab.
ANy help on this matter would be great. Thanks in advance.Hi,
Try adding a target attribute to you link:
'<a href="javascript:popupURL(''http://www.google.com'')" target="_blank">LINK</a>'
Regards,
Vincent -
Case Statement with excel data source
When trying to create a case statement in the RPD I get the following error in answers when selecting from the column.
Listed is the RPD column select statement CASE EMPHOURS.EMPHOURS_DIM.PAYCODE WHEN 'OT' THEN 'Overtime' END
Listed is the error I receive in answers:
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: 37000 code: -3100 message: [Microsoft][ODBC Excel Driver] Syntax error (missing operator) in query expression 'case T24.[PAYCODE] when 'OT' then 'Overtime' end'.. [nQSError: 16014] SQL statement preparation failed. (HY000)
The statement works fine when I use oracle RDBMS as the data source and not excel.
RegardsHi Sophia,
Could you please edit Database>Features in this there will be a feature "CASE_IF_SUPPORTED" and another CASE related feature which you need to change and check in this features.
Regards,
Som -
Hiding Entire Row having Null and default valu in SSRS Using Expression
Hi,
In my reports having number of rows and three columns.The first columns value will be different for each and every row and it will be hard corded to the text box. My question is how to hide the particular row second and third column suppose
to be null or empty data and each and every row had Hide is true.Please provide me the solution if anybody known.
Regards,
HariKan
HariKanHi Qiuyun Yn,
Thanks for your reply.
If i use Not Null in my query in where
condition then i have to add 30 fields in my where condition, and i guess it will not give proper output why because i have 30 columns.
So could you please give me in report level solution. I am struggling past 10 days for this issue.
Regards,
Hari
HariKan -
Multiple case statements with aggregates- SQL
Hi guys
Here is my ddl
create table TestTable
Bill_date DATE,
Phone_no NUMBER(10),
Planlvl1 VARCHAR2(20),
Planlvl2 VARCHAR2(20)
Revenue NUMBER
INSERT INTO TestTable
Values
('1/01/2014' , 64221, 'Bundle', 'SpecialPack1', '$23'),
('1/01/2014'' , 64221, 'Bundle', 'PlanA', '$32'),
('1/01/2014' , 65211, 'Bundle', 'SpecialPack2', '$3'),
('1/01/2014' , 65211, 'Bundle', 'SpecialPack1', '$23'),
('1/01/2014' , 66211, 'Bundle', 'PlanB', '$34'),
('1/01/2014' , 66211, 'Bundle', 'SpecialPack2', '$3'),
('1/01/2014' , 66222, 'Bundle', 'SpecialPack1', '$23'),
('1/01/2014' , 66222, 'Bundle', 'SpecialPack2', '$3'),
('1/01/2014' , 66222, 'Bundle', 'PlanB', '$65'),
('1/01/2014' , 32444, 'Non_bundle', 'Casual1', '$32'),
('1/01/2014' , 324441, 'Non_bundle', 'Casual2', '$76'),
('1/01/2014' , 65444, 'Non_bundle', 'Casual1', '$12'),
('1/01/2014' , 65444, 'Bundle', 'PlanB', '$98'),
('1/01/2014' , 54322, 'Bundle', 'PlanA', '$12'),
('1/01/2014' , 54322, 'Non_bundle', 'Casual', '$12')
Expected Outcome:
Bill_date PlanLvl2 PhonenoCount
'01/01/2014' 'SpecialPack1' 1
'01/01/2014' 'SpecialPack2' 3
'01/01/2014' 'Casual1' 1
'01/01/2014' 'Casual2' 1
'01/01/2014' 'PlanA' 1
'01/01/2014' 'PlanB' 1
Basically I have to count all the phone nos grouped by plans in a certain way:
If PlanLvl1 = Bundle, then I have to look at planLvl2 and see if that phone no has ' SpecialPack%' ,and also another plan,them 'Special pack' gets the priority and the phone no gets counted in the special pack.
In case when PlanLvl1 = Bundle and a phone no has both 'Special Packs' as their plans, then the phone no will be counted under the 'Special Pack' with higher Revenue.
In case where PalnLvl is 'Bundle' and a phone no has multiple 'Special Packs' and a non special, that ph no will only be counted once under 'Special Pack; of higher rev as compared to the special pack of lower rev.
Now there are also PlanLvl1 which are 'Non_Bundles' which means they do not have any 'SpecialPacks' but if a ph no with 'NonBundle' plan has 2 different plans under planLvl2, we need to count that ph no for eack planLvl2..
Then there is a scenario where a ph no can have bundles as well as non bundles and in that case we just have to count that ph no in bundles and not in non-bundles.
As I mentioned , 'SpecialPack2' will get a preference over special pack 1 if a phone no has got both of these
Hope this helpsI;m not sure exactly what your rules are since you specify both "In case when PlanLvl1 = Bundle and a phone no has both 'Special Packs' as their plans, then the phone no will be counted under the 'Special Pack' with higher Revenue" and "As I mentioned ,
'SpecialPack2' will get a preference over special pack 1 if a phone no has got both of these". I went with the rule "As I mentioned , 'SpecialPack2' will get a preference over special pack 1 if a phone no has got both of these" since that seemed to match
the result you say you want. I also changed the datatypes to valid SQL Server datatypes.
create table TestTable
Bill_date DATE,
Phone_no Decimal(10,0),
Planlvl1 VARCHAR(20),
Planlvl2 VARCHAR(20),
Revenue money
INSERT INTO TestTable
Values
('1/01/2014' , 64221, 'Bundle', 'SpecialPack1', '$23'),
('1/01/2014' , 64221, 'Bundle', 'PlanA', '$32'),
('1/01/2014' , 65211, 'Bundle', 'SpecialPack2', '$3'),
('1/01/2014' , 65211, 'Bundle', 'SpecialPack1', '$23'),
('1/01/2014' , 66211, 'Bundle', 'PlanB', '$34'),
('1/01/2014' , 66211, 'Bundle', 'SpecialPack2', '$3'),
('1/01/2014' , 66222, 'Bundle', 'SpecialPack1', '$23'),
('1/01/2014' , 66222, 'Bundle', 'SpecialPack2', '$3'),
('1/01/2014' , 66222, 'Bundle', 'PlanB', '$65'),
('1/01/2014' , 32444, 'Non_bundle', 'Casual1', '$32'),
('1/01/2014' , 324441, 'Non_bundle', 'Casual2', '$76'),
('1/01/2014' , 65444, 'Non_bundle', 'Casual1', '$12'),
('1/01/2014' , 65444, 'Bundle', 'PlanB', '$98'),
('1/01/2014' , 54322, 'Bundle', 'PlanA', '$12'),
('1/01/2014' , 54322, 'Non_bundle', 'Casual', '$12')
;With cte As
(Select Bill_date, Phone_no, Planlvl1, Planlvl2, Revenue,
Row_Number() Over (Partition By Bill_Date, Phone_no Order By
Case When Planlvl1 = 'Bundle' And Planlvl2 Like 'SpecialPack2' Then 0 Else 1 End,
Case When Planlvl1 = 'Bundle' And Planlvl2 Like 'SpecialPack1' Then 0 Else 1 End,
Case When Planlvl1 = 'Bundle' Then Revenue Else -1 End Desc) As rn,
Min(Case When Planlvl1 = 'Bundle' Then 0 Else 1 End) Over(Partition By Bill_Date, Phone_no) As NumberHasOnlyNonBundle
From TestTable)
Select Bill_date, Planlvl2, COUNT(*) As PhoneNoCount
From cte
Where rn = 1 Or NumberHasOnlyNonBundle = 1
Group By Bill_date, Planlvl2;
Tom -
declare @servdate datetime
declare @paiddate datetime
set @servdate='12/1/2015'
set @paiddate='1/30/2016'
select case
when YEAR(@servdate)=YEAR(@paiddate) and MONTH(@servdate) IN (9,10,11) and MONTH(@paiddate) in (9,10,11) then 'Q1'
when YEAR(@servdate)+1=YEAR(@paiddate) and MONTH(@servdate) IN (12) and MONTH(@paiddate) IN (1,2) then 'Q2' ELSE '' END +
case when YEAR(@servdate)=YEAR(@paiddate) and MONTH(@servdate) IN (12) and MONTH(@paiddate) in (12) then 'Q2'
when YEAR(@servdate)=YEAR(@paiddate) and MONTH(@servdate) IN (3,4,5) and MONTH(@paiddate) in (3,4,5) then 'Q3'
when YEAR(@servdate)=YEAR(@paiddate) and MONTH(@servdate) IN (6,7,8) and MONTH(@paiddate) in (6,7,8) then 'Q4'
else 'NQ' end
I`m trying to derived Quarters in my query by using case expression. The Qtr logic is When Servdate and Paid date
are '9/1/2014 and 11/30/2014 then its FiscalYear2015 Q1,
When
Servdate and Paid date
are '12/1/2014 and 02/28/2015 then its FiscalYear2015 Q2,
When
Servdate and Paid date
are '3/1/2015 and 05/31/2015 then its FiscalYear2015 Q3,
When
Servdate and Paid date
are '6/1/2015 and 08/31/2015 then its FiscalYear2015 Q4,
With the above code snippet I`m using I think its working for all quarters except Q2 with above dates I get in my resultset
" Q2NQ " .. Do i need to use a OR predicate am i missing something?
FMselect case when YEAR(@servdate)=YEAR(@paiddate) and MONTH(@servdate) IN (9,10,11) and MONTH(@paiddate) in (9,10,11) then 'Q1'
when YEAR(@servdate)+1=YEAR(@paiddate) and MONTH(@servdate) IN (12) and MONTH(@paiddate) IN (1,2) then 'Q2'
when YEAR(@servdate)=YEAR(@paiddate) and MONTH(@servdate) IN (12) and MONTH(@paiddate) in (12) then 'Q2'
when YEAR(@servdate)=YEAR(@paiddate) and MONTH(@servdate) IN (3,4,5) and MONTH(@paiddate) in (3,4,5) then 'Q3'
when YEAR(@servdate)=YEAR(@paiddate) and MONTH(@servdate) IN (6,7,8) and MONTH(@paiddate) in (6,7,8) then 'Q4'
else 'NQ' end -
I have a problem. I have this SQL :
select SLA_MET_TAB.SLA_MET_COL, count(*),((count(*)/Total)*100), Total
from
(select (case
when (completion_date - approval_date) -
(case
when to_char(approval_date,'D') < 5 then 0
when to_char(approval_date,'D') = 5 then 3
when to_char(approval_date,'D') = 6 then 2
when to_char(approval_date,'D') = 7 then 1
end -
case
when to_char(approval_date,'hh24') > 15 then 1
when to_char(approval_date,'MI') > 0 and to_char(approval_date,'hh24') = 15 then 1
else 0
end -
case
when completion_date in (select holiday from csacweb_owner.holiday) then 1
else 0
end)< 1.375 then 0
else 1
end) SLA_MET_COL
from csacweb.orders
where community_id = 166 and completion_date is not null and approval_date is not null) SLA_MET_TAB,
(select count(*) Total from csacweb.orders where community_id = 166)
group by SLA_MET_TAB.SLA_MET_COL, Total;
Then problem is that when I'm trying to execute, I always have an error message that says : not a GROUP BY expression ... anyone can help me ?Which version of the database are you running? This simplification of your query runs on my 9.2.0.6 install...
SQL> select object_type, count(*) as my_funcs, total as all_funcs, count(*)/total as pct
2 from all_objects o
3 , ( select count(*) as total from all_objects
4 where object_type = 'FUNCTION' )
5 where o.object_type = 'FUNCTION'
6 and o.owner = USER
7 group by object_type, total
8 /
OBJECT_TYPE MY_FUNCS ALL_FUNCS PCT
FUNCTION 1 48 .020833333
SQL> Cheers, APC -
How to get my apple I'd off a macbook pro with having to giv my I'd and password away
I had sold my macbook pro to someone and they say they can't update the computer without my I'd, the problem I am confused about Is when ii gave him the computer I already restore the computer to not need my apple I'd, is there anything he can do without me needed to give h my Id anddd password so he can update
When you sell a MacBook Pro, you need to give them the original OS that was installed on it when it shipped from Apple. Any upgrades you purchased from teh Mac App Store (even the free "purchase" of Mavericks) is tied to your Apple ID. You would need to restore the Mac to the original OS, then let the buyer upgrade the OS themselves.
-
Case statement with where clause.
I appreciate that there are much simpler ways to run this query but I wondered if anyone else had come across the following -
select distinct
product_table.a,
product_table.b,
product_table.c,
CASE WHEN product_table.c IN ('A','AA') THEN 'AAA'
WHEN product_table.b = 'B' THEN 'BBB'
WHEN product_table.c IN ('C','CC','CCC') THEN 'CCC'
WHEN product_table.b IN ('D','DD') THEN 'DDD'
WHEN product_table.b LIKE 'E%' THEN 'EEE'
WHEN product_table.b LIKE 'F%' THEN 'FFF'
WHEN product_table.b LIKE 'G%' THEN 'GGG'
ELSE 'UNKNOWN' END
from product_table
where
( CASE WHEN product_table.c IN ('A','AA') THEN 'AAA'
WHEN product_table.b = 'B' THEN 'BBB'
WHEN product_table.c IN ('C','CC','CCC') THEN 'CCC'
WHEN product_table.b IN ('D','DD') THEN 'DDD'
WHEN product_table.b LIKE 'E%' THEN 'EEE'
WHEN product_table.b LIKE 'F%' THEN 'FFF'
WHEN product_table.b LIKE 'G%' THEN 'GGG'
ELSE 'UNKNOWN' END) = 'FFF'
when this query runs its as if the where clause = 'FFF' does not exist and all rows are returned.
Thanks, Sarah.Technical questions should be addressed to one of the technical forums. You'll probably find that the folks in the PL/SQL forum (Products | Database | PL/SQL) have some thoughts.
Justin
Distributed Database Consulting, Inc.
http://www.ddbcinc.com/askDDBC
Maybe you are looking for
-
BSOD when start transfering data
Hello. Im install latest itunes at my new computer with win xp sp3 and when i connect my ipod and try to send some new music\cinema i got blue screen of death. Error name - IRQLNOT_LESS_OREQUAL. When im just connect my ipod all work. When i start tra
-
Disabling auto scroll in Flex Navigator
Hi. How do I disable the vertical autoscroll, when I use the Flex Navigator. When I click a file in the Flex Navigator, it centers the file vertically in the Flex Navigator, byt when I go up or down the "tree" it autoscrolls left and right, depending
-
Ibooks crashes on my iMac 100% of the time..
Why does iBooks crash on my iMac 17 intel.. It does not do the same thing on my MacBook Pro ?
-
W3.2: What is 3.2 doing with Sysdeo DevLoader?
"Automatic Sysdeo installation and configuration for Tomcat. " What is it doing? Is there a relationship to .#webclasspath? What does it mean? We are having trouble referencing an .jar application into a web application, and we have the feeling that
-
Hello, I seek the wisdom of the Labview Gurus. I have a VI that I can succesfully create objects and display my data. I can then manipulate the position and do a host of other things that I need done. Unfortunately, I cannot seem to figure out the