Neeed help to write a case statement
I want to write a case statement such that
i have four name sunny,katie,linda,scott in which sunny is the manager
the rek is that under sunny if katie,linds scott falls then i need to show "yes" in coloumn other wise "no"
like
case when cn1.sunny=cn2 in(katie,linda,scott) then 'y' else 'n'
Edited by: user13001889 on Jun 20, 2011 1:04 PM
What is a table structure? Sorry cannot test it right now..
SELECT <columns>,(SELECT Total FROM tbl WHERE Y=2014)-(SELECT Total FROM tbl WHERE Y=2013)
FROM tbl
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence
Similar Messages
-
Please Help!!!
How to write a case statement for the totals column of two different years (2013 and 2014) of the same month so that I can get a +/- column.
January 2014 January
2013 +/-
Region Entry Exit Total Entry Exit Total (Total of Jan2014-Total of Jan2013)
A 2 3
40 5 7 30 40-30= 10What is a table structure? Sorry cannot test it right now..
SELECT <columns>,(SELECT Total FROM tbl WHERE Y=2014)-(SELECT Total FROM tbl WHERE Y=2013)
FROM tbl
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence -
How do I write a case statement If I want a case for x < 1.5; a case for 1.5 <= x <= 3.7; case for 3.7 < x < 7.2.....etc. My input is a floating number.
Thank you.
Solved!
Go to Solution.smercurio_fc wrote:
Nice method with the Threshold function. I was not aware of the limitation with -Inf. Odd.
Actually, my code operates correctly as long as the first element is smaller than all other elements in the array. We don't need any special handling.
Maybe NaN is not a bug if the array starts with -Inf, because the interpolated index for any number between the second element and -inf will be infinitely close to 1, thus a result of zero can never be obtained (try a first element of -1e50 and you'll always get 1 unless you go to very huge negative numbers).
The way threshold array is defined, the behavior should be obvious, the problem is assigning a fractional index.
It is unexpected that an input equal to the second element also results in NaN. That might be a bug. (see image).
I probably won't post an idea, maybe a bug report after some more thinking...
LabVIEW Champion . Do more with less code and in less time .
Attachments:
IdeaThresholdArray.png 19 KB -
Help: How to use Case statement in Interface ODI11g?
Hi
From my Source base i am getting 'Year' Values and i want translate these values into a code in interface and after translate want to push to Target system.
Example:
From source Database i am getting value for
Year
2010
2011
2012
When i get Year 2010 i want to modify value into 'FY10'
when i get Year 2011 i want to modify value into 'FY11'
and same for Year 2012 TO 'FY12'
I was trying to do by Case statement but didn't got success.
I dont want to create Lookup table in source system.
Any help in this regards.
Thanks
Regards
Sher
Edited by: Sher Ullah Baig on Aug 26, 2012 5:52 PMCASE
WHEN source_column='2010' THEN 'FY10'
WHEN source_column='2011' THEN 'FY11'
WHEN source_column='2012' THEN 'FY12'
END -
BuffferWriter dosen't write in case statement
Hi all,
In the following code snippet below, bufferwriter does no write “***Choice not found” In the logfile can anyone explain why?
When bufferWriter is called outside the case statement , the file is written to i.e. "Opened Log File" and 'Closed Log File" is written to the file.
BufferedWriter my_Logger = new BufferedWriter(new FileWriter("theLogFile.LOG"));
my_Logger.write("Opened Log File");
my_Logger.newLine();
switch (month) {
case 1: System.out.println("One"); break;
case 2: System.out.println("Two"); break;
default:
my_logger.write("***Choice not found");
my_Logger.newLine();
my_Logger.write("Closeded Log File");
my_Logger.newLine();1. How are you sure that month is not 1 or 2?
2. If you're not writing anything after the "missing" log statement, or at least not writing enough to fill up the buffer, the BufferedWriter may be hanging onto the characters until its buffer is full. Try calling flush(), or, if you're done with it, close().
If that doesn't solve it, provide an [url http://sscce.org]SSCCE. -
Need help in using a case statement in expression operator
Hi All,
I am using OWB version 10.2.0.1.0.
My requirement is to add a new column called call _zone_key in expression operator and map it to the target table. I need to use the below expression for populating call_zone_key values
Expression:
case when (INGRP1.CHARGETYPE in ('O','F') or INGRP1.TARIFF_GROUP in ('SMSINT','MMSINT')or ( INGRP1.CALL_TYPE = '002' and INGRP1.TARIFF_GROUP = 'MTV'))
then
(select call_zone_reltn_key from call_zone_reltn where
call_zone_cd=substr(case
when substr( INGRP1.B_SUBNO,1,2)='00'
then
substr( INGRP1.B_SUBNO,3)
else substr( INGRP1.B_SUBNO,1)
end,1,length(call_zone_cd))and rownum=1)
else -1
end
All the columns needed for using the above expression is available in INGRP1 but still I am unable to deploy the mapping using above expression. Call_zone_reltn table is also imported to the module. I am getting below error
Error:
Warning
ORA-06550: line 4980, column 2:
PLS-00103: Encountered the symbol "SELECT" when expecting one of the following:
( - + case mod new not null others <an identifier>
<a double-quoted delimited-identifier> <a bind variable> avg
count current exists max min prior sql stddev sum variance
execute forall merge time timestamp interval date
<a string literal with character set specification>
<a number> <a single-quoted SQL string> pipe
<an alternatively-quoted string literal with character set specification>
<an alternativ
NEW_MOD_MAP_CELL_USAGE_FCT_PRE
Create
Warning
ORA-06550: line 4989, column 43:
PLS-00103: Encountered the symbol ")" when expecting one of the following:
* & - + ; / at for mod remainder rem <an exponent (**)> and
or group having intersect minus order start union where
connect || multiset
If i replace the expression with numbers such as 1 or 2, I am able to deploy the mapping.
Kindly help in fixing this issue.
Thanks,
KabilanYou can't use the SELECT statement inside the expression, you need to join both tables before the expression. Use a Join operator with this JOIN condition:
CALCULATED_CALL_ZONE_CD = call_zone_reltn.call_zone_cd ( + )
Where Calculated_call_zone_cd proceed from a previous expression:
CALCULATED_CALL_ZONE_CD = substr(case when substr( INGRP1.B_SUBNO,1,2)='00' then substr( INGRP1.B_SUBNO,3) else substr( INGRP1.B_SUBNO,1) end,1,length(call_zone_cd))
And after joining both tables, you can use another expression to get the rownum, then another filter operator to keep only the rownum = 1, and now you can use your expression without the SELECT, using the call_zone_cd column from the outgroup in the joiner operator (you need to include that column in the filter operator to use it).
Regards
ANA GH -
Please Help: Trouble with nested CASE statement and comparing dates
Please tell me why the query below is always returning the bold null even when the start_date of OLD is greater than or equal to the start_date of NEW.
What I want to do is get the difference of the start_dates of two statuses ( Start_date of OLD - Start_date of NEW) if
1. end_date of NEW is not null
2. start_date of OLD is greater than start_date of NEW
else return null.
select id,
case when max(end_date) keep (dense_rank last order by decode(request_wflow_status,'New',1,0),start_date) is null then
null
else
case when max(decode(status,'OLD',start_date,null)) > max(decode(status,'NEW',start_date,null))
then max(decode(status,'OLD',start_date,null)) - max(decode(status,'NEW',start_date,null))
else
null
end
end result
from cc_request_status where id =1
group by id;Avinash,
Thank you for your help.. Here is a more description of my problem..
Here is a sample of data I have for a table with four columns (id,status,start_date,end_date)
What I need to do is to get difference of the start dates of the maximum available dates, if data is valid. The pseducode is as follows:
IF end_date of New status is null
THEN return null
ELSE
IF start_date of old >= start_date of new
THEN return (start_date of old - start_date of new)
ELSE return null
I used the following query but always return the bold null
select id,
(case when max(end_date) keep (dense_rank last order by decode(status,'new',1,0),start_date) is null then
null
else
(case when max(decode(status,'old',start_date,null)) >=
max(decode(status,'new',start_date,null))
then max(decode(status,'old',start_date,null)) - max(decode(status,'new',start_date,null))
else
null
end)
end) result
from tbl where id =1
Based on the below sample, I expected to get the following result; 14-Mar-07 - 16-Feb-07 which is the difference of the maximum start_dates of the two statuses. However the query is not working.. Please help me.. Thank you..
Id Status start_date end_date
1 new 03-Feb-07 07-Feb-07
1 new 16-Feb-07 21-Feb-07
1 old '10-Mar-07 12-Mar-07
1 old '14-Mar-07 16-Mar-07 -
Help with error select case statement (ORA-00932: inconsistent datatypes)
Hi,
I'm struggling to get my sql query work on Oracle..
I have a table MyTable with 5 columns ( Column1, Column2, Column3, Column4, Column5 ) all are of type NVARCHAR2.
I need to check whether Column 3, Column 4 are empty or not in that order..and if they values then I wanna append it to Column2.
For example
If a row contains the following values,
Column 2 = a.b
Column 3 = 123
Column 4 = xyz
then column CA = a.b/123/xyz where column CA = temp column
If either Column 3 or Column 4 is empty/null, then I don't need to append value for that column..
For example
Column 2 = a.b
Column 3 = either NULL or ''
Column 4 = xyz
then CA = a.b/xyz where column CA = temp column
similarly..
Column 2 = a.b
Column 3 = 123
Column 4 = either NULL or ''
then CA = a.b/123 where column CA = temp column
Here is my query..
select MyTable.Column1 as CA0,
MyTable.Column2 as CA1,
MyTable.Column3 as CA2,
MyTable.Column4 as CA3,
MyTable.Column5 as CA4,
MyTable.Column2 + CASE WHEN MyTable.Column3 > '' THEN '/' + MyTable.Column3 ELSE '' END + CASE WHEN MyTable.Column4 > '' THEN '/' + MyTable.Column4 ELSE '' END CA
from MyTable;
This query works just fine against SQL Server db, but gainst Oracle I'm getting
ORA-00932: inconsistent datatypes: expected NUMBER got CHAR
00932. 00000 - "inconsistent datatypes: expected %s got %s"
Could you please let me know what I'm doing wrong. I need to get this query working on both SQL Server and Oracle..
Please let me know your suggestions and thoughts..
Cheers,I need to check whether Column 3, Column 4 are empty or not in that order..and if they values then I wanna append it to Column2. In Oracle, you can do it this way - no need to do all kinds of difficult things:
select col2||col3||col4
from tbl -
Help with decode or case statement
I have the following insert statement
insert into t_outcome (
TRANSACTION_ID,
charge_DATE,
Charge_TIME,
STATUS_CODE)
values(cur_tem.transaction_id,
cur_tem.charge_date,
cur_tem.charge_time,
cur_tem.STATUS_code)
I require to incorporate the following rules into the population of charge_TIME
if cur_tem.STATUS_code is 7 and cur_temp.charge_time is not null then populate charge_TIME with cur_temp.charge_time
else if cur_tem.STATUS_code is 7 and cur_temp.charge_time is null then populate charge_TIME with -9
else if cur_tem.STATUS_code is not 7 then populate charge_TIME with -7
How do I add these rules into the insert statement ?
Thanks
Brendondecode(cur_tem.STATUS_code, 7, nvl(cur_tem.charge_time, -9), -7)
I think that will work.
Lee
Message was edited by:
Lee Forkenbrock -
Case Statement Help needed [Nested]
Hi all,
I need to write a case statement my requirement is
ENC.EET.40 E_Disposition populated from either “E_ Status” field of HP_Response_table, “File Status” of HP _TTT_Response_Table,
or “E_Status” of DDA_R_Table. If no data in any of these fields, default to “Submitted”
So my case stmt should look like
case when E_Status is null then 'SUBMITTED'
when e_status is null then 'Submitted'
when FileStatus is null then 'Submitted'
Else case when E_status is not null then ............?????????????
else case when
Im Confused.. Can someone help me ?
FMselect ...
coalesce (resp.E_Status, resp2.FileStatus, dda.E_Status, 'Submitted')
from ...
Obviously I have used alias for the respective tables according to your logic. -
Unable to write more than 10 case statements in an object in designer
unable to write more than 10 case statements in an object in designer
XI 3.0 and XI 3.1
Please let me know, any known issues.Hi,
yes this is the limitation you cant write more that 10 case statments but you can reduce the number of time you use the case in your object.
For ex:
If you are writing few conditions on one field then you can add the login in one case only.
case when SAL between 100 and 1000 then 'lowsal'
when SAL between 1000 and 2000 then 'medsal'
when sal between 2000 and 3000 then highsal
else
case when ...then ....
else
end
end
by following the above ex you can solve your problem.
But if you are writing case statement based on dofferent columns then write 10 case statements and remaining conditions you can add at the report level.
using if else condition.
Hope this will help you....
Cheers,
Ravichandra -
Help: How to include logic in multiple CASE statements.
Hello Folks,
I have this Query where am converting from Access to Oracle. Am little confused on how to write multiple CASE statements.Apprecitae your help.
round(Sum(IIf(recovery_flg = 'NONCASH FEE RECEIVED',
IIf(feepaid < FEE, FEE - FEEPAID, FEE),
0)),
2)*(1) you can nest CASE* - CASE in a CASE
CASE WHEN ecovery_flg = 'NONCASH FEE RECEIVED' THEN
CASE WHEN feepaid < FEE THEN ....
END
ENDor
*(2) you can try to rewrite it as one CASE*
CASE WHEN ecovery_flg = 'NONCASH FEE RECEIVED' AND feepaid < FEE THEN...
WHEN ecovery_flg = 'NONCASH FEE RECEIVED' AND feepaid >= FEE THEN ...
END -
Formatted search case statement help
Hi all,
I am trying to write a case statement in a formatted search, but am running into an error when I add a condition involving the item code. The code works find with the first WHEN statement involving the customer code $[$4.0.0] however, I receive an internal error when I add the second part involving the item code $[$38.1.1] Please advise.
SELECT
CASE WHEN $[$4.0.0] = 'C00023'
THEN 'E002'
WHEN $[$38.1.1] = 'ItemA'
THEN 'J002'
END
THank you!
JaneHi Jane,
Where do you assign this FMS? If it is on the header, the second condition will not work. If it is line level, try change it to $[$38.1.0\].
Thanks,
Gordon -
Please help me with a CASE Statement:
- When ID = 15, 16, 17, 18 then "Bad"
- when ID = 19, then "Average"
- when ID = 21, then "Good"
- else "Null"
Thank you!!Well the 1st thing to do would be to correct my poor spelling... change Delault : to Default :
Don't know why you would get an error stating "The result of selection formula must be a boolean". It's working fine on my machine.
If your ID field is numbers stored text you have a couple different options...
1) Convert the ID to a number...
Select ToNumber({home.noone_ID})
2) Wrap the ID values in double quotes...
Case "15", "16", "17", "18" :
"BAD"
Even if this were your problem... the error should be something other than the boolean thing...
Jason -
Case statement on Variable SSIS
Hi friends,
I have a small issue in my package I would like to write a case statement on Variable or Column in derived column Transformation
I was using forloop container that pulls the data from different database so the database names also loading into table under one of the column but I wanna load with integer value instead database name
for example
Database A -- 1
Database B -- 2
so I would like to write a case statement on variable or column but It was not allowing me to write when I tried.
what I have tried was I took one derived transformation and added one new column and passed that variable to that new column.
then again I took another derived transformation here I was trying to write case statement on the colum which is belongs to previous derived column.
Derived Column Tran 1:
Derived Column Name Expression DataType
RegionID @[User::InitialDB] Unicodestring[DT_WSTR]
Derived Column Tran2:
Can anyone please check and guide me the solution please.
Thanks for your helpHi BandSr,
You were close, just missing the false part in your second conditional operator.
[RegionID] == "KAPS" ? "1" : [RegionID] == "LAPS"? "2" : ""
In fact, I won't call that a Case statement but rather a nested conditional expression.
Hope this helps.
~ J.
Maybe you are looking for
-
Why can I no longer make payments to itunes with my debit card?
I have for many years used my ebit card as the method of payment on my account, but last month it failed and now wont accept the details at all. Any help welcome as I dont have a credit card.
-
IDevices and Apple composite AV Cable - Not Working
Hi... I've had problems connecting my iPods (iPod 30GB Video 5.5Gen, iPod Touch 1st and 2nd Gen, with latest capable software up to date) and my iPhone 4 (iOS 6 up to date) to my Samsung LED TV Series 5 using the original, Apple, composite AV cable.
-
How do I combine my two iTunes accounts?
I had one iTunes account a few years back when I had an iPhone and have several purchased movies and music but I can't get into that account. I must be trying thr right password. Anyway, my husband bought me an iPad for my birthday and I set up ano
-
Hi to all, I would to use simple functions in my jsp page. I 've created the function with the tags <%! ... %> My problem is that i don't succed to call there from the page. How i can to do ? I've tried also with java beans but i'm not very clever wi
-
I try to find a way to exclude Special G/L Transactions in FDM_COLL01 and Worklist (Process Receivable). Whenever a transaction is created in AR, it immediately shows up in FDM_COLL01, regular or special GL transactions.