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.
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 -
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 PMWhat 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 -
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 -
Trying to use greater than in a case statement
What is the correct way to write this case statement?
Case
F.NextOrder2
> F.CutOff
Then
Else F.NextOrder2
as NextOrder3You're missing END, e.g.
CASE when F.NextOrder2 > F.CutOff then '' else cast(F.NextOrder2 as varchar(100)) end as NextOrder3
All values in the CASE statement must be of the same data type.
See this blog post why
SQL Server Case/When Data Type problems
Premature optimization is the root of all evil in programming. (c) by Donald Knuth
Naomi Nosonovsky, Sr. Programmer-Analyst
My blog -
Appying formula in case statement
Hi ,
I have a query which is i have to 2 columns say revenue, grossmargin. I need to apply a formula on
gross margin such as if revenue is less than zero the gross margin=0. I tried to write in case statement on GrossMargin as below
if Revenue > 0 then GrossMargin
else GrossMargin='0' end.
The above code throws error.
Can anyone pls suggest solution?.
Regards,
Venki.Try with this:
CASE
WHEN revenue > 0 THEN GrossMargin
ELSE 1=1 THEN '0'
END
This sentence means that if revenue > 0 then return value of GrossMargin, if not evalue 1=1 (it's always true) and then return '0'.
Regards. -
Problem to identify values in a case statement.
Hi Friends,
Total number of records in my report should be divided by 5 and to be alloted into 5 grades in Grade column.
This is what I have done so far in my report with following layout.
S.No - Col A - Col B - Col C - Grade ( Colums A,B,C will be hidden in Report)
*****Column C will have only 5 values at max ( 0.0, 0.2, 0.4, 0.6, 0.8).The below example is for 6 records in a report.The same will be applied for 7,8,9,10 records.
In column A: MAX(cast(RCOUNT(1) AS DOUBLE))/5 ( Ex : 6/5 = 1.2)
In Column B: Truncate(MAX(cast (RCOUNT(1) as double)/5), 0) ( Ex : 6/5 = 1.0)
In Column C: Col A- Col B ( EX:1.2 - 1.0 =0.2)
(MAX(cast(RCOUNT(1) AS DOUBLE))/5 - Truncate(MAX(cast (RCOUNT(1) as double)/5), 0))
Now In Grade coulum I want to use this column C to Grade the records with case statements in it.
I am trying to use the following case statement for Grade Coulmn
Case
when (MAX(cast(RCOUNT(1) AS DOUBLE))/5 - Truncate(MAX(cast (RCOUNT(1) as double)/5), 0)) = 0.0 then .........
when (MAX(cast(RCOUNT(1) AS DOUBLE))/5 - Truncate(MAX(cast (RCOUNT(1) as double)/5), 0)) = 0.2 then .............
when (MAX(cast(RCOUNT(1) AS DOUBLE))/5 - Truncate(MAX(cast (RCOUNT(1) as double)/5), 0)) = 0.4 then .............
when (MAX(cast(RCOUNT(1) AS DOUBLE))/5 - Truncate(MAX(cast (RCOUNT(1) as double)/5), 0)) = 0.6 then ........
when (MAX(cast(RCOUNT(1) AS DOUBLE))/5 - Truncate(MAX(cast (RCOUNT(1) as double)/5), 0)) = 0.8 then .....
end
Case statement works gud for 0.0 but not for other 4 values.
It is unable to identify other 4values.
Please tell me, how can I make case statement work for all values in above scenario.
Thanks in Advance,
Varsha.
Edited by: Varsha on Nov 28, 2010 6:23 PMIn column A: MAX(cast(RCOUNT(1) AS DOUBLE))/5 ( Ex : 6/5 = 1.2)
In Column B: Truncate(MAX(cast (RCOUNT(1) as double)/5), 0) ( Ex : 6/5 = 1.0)
In Column C: Col A- Col B ( EX:1.2 - 1.0 =0.2)
(MAX(cast(RCOUNT(1) AS DOUBLE))/5 - Truncate(MAX(cast (RCOUNT(1) as double)/5), 0))Change the formula a bit by adding the by dim value for the MAX column.
Column A: MAX(cast(RCOUNT(1) AS DOUBLE) by DimTable.Column)/5
Column B: Truncate(MAX(cast (RCOUNT(1) as double) by DimTable.Column)/5, 0)
Column C: MAX(cast(RCOUNT(1) AS DOUBLE) by DimTable.Column)/5 - Truncate(MAX(cast (RCOUNT(1) as double) by DimTable.Column)/5, 0)
now write a case statement on top column c, based on your logic every 5th record will have a value 0.0
Note: Dimtable.column is the table.column for which the row count is taken.
Thanks,
Vino -
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. -
Case statement within where clause
How can i write a case statement within Where clause of SQL statement.
Ex:
If sysdate is less than Dec 31 of 2009 then run the query for 2009 else run the query for 2010.
belwo query is not working. Please let me know how can i write a case statement within where clause.
Select * from table
where
Case
when to_char(sysdate,'yyyymmdd')<=20091231 then tax_year=2009
else tax_year=2010
EndHi,
You can get the results you want like this:
Select *
from table
where tax_year = Case
when to_char(sysdate,'yyyymmdd') <= 20091231
then 2009
else 2010
End
;A CASE expression returns a single value in one of the SQL data types, such as a NUMBER, VARCHAR2 or DATE. There is no boolean type in SQL. -
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
; -
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 -
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. -
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 -
Case statements to count Contact numbers
Hi,
I'm trying to use CASE IF or WHEN statements to count simple Contact numbers by owner or region. I need to count the following in separate fields of course:
Number of contact type = Customers
Number of Contact types = Propects
Number of Contacts at each seniority level (6 levels)
Number of contact validated (tick box)
I presume I need to write a CASE statement that I can then use to Sum for each column but I'm struggling with CASE statements to apply an CASE IF Column equals 'Customer' then count 1 for example. Never done these before so any help or advice greatly appreciated.
Contact type field is Contact."Contact Type"
Contact Seniority is Contact.PICK_3
Thanks,
Chrishere is an example:
sum (case when contact type = 'Customers' then 1 else 0 end)
Do the same for the second and forth in your list as above ;
include the Contact.PICK_3 and # of contact fields in step 1;
add region, owner, # of Customers, # of Prospects and # of validated in row section of your pivot view;
add Contact.PICK_3 to column section;
add # of contact to the measurement section.
Maybe you are looking for
-
Since updating to Mountain Lion OS (January 6th 2013) a few of my applications such as Logic Pro, Skype and Garageband are appearing with "this application has quit unexpectedly" as soon as I open them. Everything is up to date and it's becoming very
-
Video not working in Beatles Box Set
I just purchased The Beatles Box Set and the video "Live at the Washington Coliseum, 1964" unexpectedly quits playing after about 5 minutes in and will not resume from that point on. Anyone else have this issue?
-
Hello, I am in charge of moving an existing SAP NW BI (SPS20) from a MS SQL Server 2005 database on Windows Server 2003 (x864/64 bit) Platform to a MS SQL Server 2008 database/Windows Server 2008 Platform (x64/64 bit). The SID of the SAP system will
-
New mac..need code
hi have a new macbook (very nice) upgraded to qt pro on pld powermac this year, no record of key in my emails how do i get existing keyto upgrade QT on new mac or must i pay 4 upgrade again?
-
Coming back to Java after 1.5 years
Hi, I worked on Java earlier,1.5 years back.Its mostly on the core java.These 1.5 years i was working on various skillsets due to the projects.I am planning to switch back to Java.I am comfortable in the core java.I want to learn the J2EE technologie