How to use case when function to calculate time ?
Dear All,
May i know how to use case when function to calculate the time ?
for the example , if the First_EP_scan_time is 12.30, then must minus 30 min.
CASE WHEN FIRSTSCAN.EP_SHIFT <> 'R1' AND FIRSTSCAN.EP_SHIFT <> 'R2'
THEN ROUND(CAST((DATEDIFF(MINUTE,CAST(STUFF(STUFF((CASE WHEN SHIFTCAL.EP_SHIFT = 'N1'
THEN CONVERT(VARCHAR(8),DATEADD(DAY,+1,LEFT(FIRSTSCAN.EP_SCAN_DATE ,8)),112) + ' ' + REPLACE(CONVERT(VARCHAR(8),DATEADD(HOUR,+0,SHIFTDESC.EP_SHIFT_TIMETO + ':00'),108),':','')
ELSE LEFT(FIRSTSCAN.EP_SCAN_DATE ,8) + ' ' + REPLACE(CONVERT(VARCHAR(8),DATEADD(HOUR,+0,SHIFTDESC.EP_SHIFT_TIMETO + ':00'),108),':','') END),12,0,':'),15,0,':') AS DATETIME),CAST(STUFF(STUFF(LASTSCAN.EP_SCAN_DATE,12,0,':'),15,0,':') AS DATETIME)) / 60.0 - 0.25) AS FLOAT),2)
ELSE ROUND(CAST((DATEDIFF(MINUTE,CAST(STUFF(STUFF(FIRSTSCAN.EP_SCAN_DATE,12,0,':'),15,0,':') AS DATETIME),CAST(STUFF(STUFF(LASTSCAN.EP_SCAN_DATE,12,0,':'),15,0,':') AS DATETIME)) / 60.0) AS FLOAT),2) END AS OTWORK_HOUR
Do not use computations in a declarative language. This is SQL and not COBOL.
Use a table of time slots set to one more decimal second of precision than your data. You can now use temporal math to add it to a DATE to TIME(1) get a full DATETIME2(0). Here is the basic skeleton.
CREATE TABLE Timeslots
(slot_start_time TIME(1) NOT NULL PRIMARY KEY,
slot_end_time TIME(1) NOT NULL,
CHECK (start_time < end_time));
INSERT INTO Timeslots --15 min intervals
VALUES ('00:00:00.0', '00:14:59.9'),
('00:15:00.0', '00:29:59.9'),
('00:30:00.0', '00:44:59.9'),
('00:45:00.0', '01:00:59.9'),
('23:45:00.0', '23:59:59.9');
Here is the basic query for rounding down to a time slot.
SELECT CAST (@in_timestamp AS DATE), T.start_time
FROM Timeslots AS T
WHERE CAST (@in_timestamp AS TIME)
BETWEEN T.slot_start_time
AND T.slot_end_time;
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL
Similar Messages
-
How to use case when in Select qry?
Hi Friends,
I want to use Case when in Select qry, my situation is like this
SELECT bmatnr blgort bj_3asiz bmat_kdauf b~mat_kdpos
SUM( ( case when bshkzg = 'S' then bmenge else 0 END ) -
( case when bshkzg = 'H' then bmenge else 0 END ) ) AS qty
INTO corresponding fields of table it_projsal
FROM mseg AS b
INNER JOIN mkpf AS a ON bmblnr = amblnr
AND bmandt = amandt
WHERE abudat < '20061201' AND blgort IN ('1050')
and b~mandt = '350'
GROUP BY bmatnr bj_3asiz bmat_kdauf bmat_kdpos b~lgor
If we give like this it gives an error.
Please help me, how to use or handle in select qry itself.
Regards
Shankarthis is not a way to select data from the DB tables.
first get all the data from the DB tables then u have to do SUM Ups .
Regards
prabhu -
How to use case when statements in ODI
I need to put conditional logic before DVM look up in ODI. In the expression editor I put the following statement:-
CASE WHEN POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME='RCS' THEN POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME=EBIZ_CELL.CELL_DATA
WHEN POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME='FDC' THEN CONCAT(POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME,POC_JOURNAL_TEMP_SOURCE_TBL.BOOK_CODE)=EBIZ_CELL.CELL_DATA
END
It did not work,
Under Operators ->All Executions, found the error:-
905 : 42000 : java.sql.SQLException: ORA-00905: missing keyword
The description in Session Task contained:-
select
C1_JOURNAL_TEMPL
from APPS.POC_JOURNAL_TEMP_SOURCE_TBL POC_JOURNAL_TEMP_SOURCE_TBL, APPS.C$_0POC_JOURNAL_TEMP_TARGET_TB
where
(1=1)
And (CASE
WHEN POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME='RCS'
THEN POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME=C2_CELL_DATA
WHEN POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME='FDC'
THEN CONCAT(POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME,POC_JOURNAL_TEMP_SOURCE_TBL.BOOK_CODE)=C2_CELL_DATA
END)
Checked the above code in PL/SQL Developer but it gave errors.
In PL/SQL developer tried to check a simple query using case-when but even that is giving errors in the case-when portion.
The query is as follows:-
select phase_code, accounting_period, sum(eff_cc) as BD_Eff_QTD
from prj_detail
where
case POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME
when 'EXT'
then
1
when 'RAC'
then
2
when 'XXX'
then
3
else
end
I would like to know what is wrong with the above code.
Please let me know what is the correct way of using case-when in PL/SQL as well as in ODI.Your ODI case statement and PL/SQL Case statement both looks confusing.
You are writing case statement under where clause which is not a good practise. If you want to implement logic like-
select a,b,c from <table>
where
when cond^n^ 1 then do 1
when cond^n^ 2 then do 2
then better you seperate your query for each filter and do a union, in other words-
select a,b,c from <table>
where cond^n^ 1
union
select a,b,c from <table>
where cond^n^ 2
If you are writing case staement to retrieve a value/column (EBIZ_CELL.CELL_DATA) then no need to include it under filter.
ODI case for column EBIZ_CELL.CELL_DATA will be:
CASE
WHEN POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME='RCS'
THEN POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME
WHEN POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME='FDC'
THEN CONCAT(POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME,POC_JOURNAL_TEMP_SOURCE_TBL.BOOK_CODE)
END
Pl/SQL query-
select phase_code, accounting_period,
case POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME
when 'EXT'then 1
when 'RAC' then 2
when 'XXX' then 3
else 'default value' --- (if no else needed then can also remove else part)
end,
sum(eff_cc) as BD_Eff_QTD
from prj_detail
Suggested as per what is understood, hope it helps.
Edited by: 939451 on Jul 5, 2012 12:47 AM
Edited by: 939451 on Jul 5, 2012 12:48 AM -
How to use the AGO function to calculate the sum of the last 12 months?
year | month | amount
2009 | 01 | 100
2009 | 02 | 150
2009 | 03 | 120
2009 | 04 | 110
2009 | 05 | 155
2009 | 06 | 180
2009 | 07 | 105
2009 | 08 | 145
2009 | 09 | 200
2009 | 10 | 205
2009 | 11 | 150
2009 | 12 | 120
2010 | 01 | 225
SUM OF THE LAST 12 MONTHS OF 201001=>225+120+150+205+200+145+105+180+155+110+120+150 *1.865*
How do I do this? Could anyone help me?
Thanks.hi,
Create a dummy column in Fx
Use *Filter ( amount_col using date col= TimeStampAdd(SQLTSI_MONTH, -12 ,date_col)*
If u want to show at grand total level
Go with combine with similar request
same as u mentioned (1st criteria)
date_col, month, use the above formula (2nd criteria)
try this and let me know
Thanks,
Saichand.v
Edited by: Saichand Varanasi on Oct 7, 2010 7:27 PM -
I have a situation where i need to write a case when sql expression to fetch certain rows from a table.
How to use CASE WHEN THEN ELSE END in a report query ?
Explanation with a simple example will be of great help.
thanksThe javadoc for oracle.toplink.expressions.Expression
contains some information.
The following is an example of how to build the case statement.
This will use case to replace the keys in the caseTable with the values. The default value (the ELSE) is provided as the second argument.
Hashtable caseTable = new Hashtable(3);
caseTable.put("Bob", "Bobby");
caseTable.put("Susan", "Susie");
caseTable.put("Eldrick", "Tiger");
Expression expression = builder.get("firstName").caseStatement(caseTable, "No-Nickname").equal("Bobby"); -
How to use case function in where clause
Hi,
Suppose a table DEMO has columns
DEMO TABLE
user_id
user_name
location
In this table i have 15 users. but out of 15 users i want to use only 5 users for passing as user_name.
then how to achieve the result
1. when i pass the particular 5 user_name in where clause then i should get all the user_name and for other 10 users it will show only the passing user_name.
how to use case functionDo you mean this ?
SQL> var name varchar2(10)
SQL> exec :name := 'ALLEN'
PL/SQL procedure successfully completed.
SQL> select ename from emp where case when :name in ('SMITH','ALLEN') then ename
2 else :name end = ename;
ENAME
SMITH
ALLEN
WARD
JONES
MARTIN
BLAKE
CLARK
SCOTT
KING
TURNER
ADAMS
JAMES
FORD
MILLER
14 rows selected.
SQL> exec :name := 'SMITH'
PL/SQL procedure successfully completed.
SQL> select ename from emp where case when :name in ('SMITH','ALLEN') then ename
2 else :name end = ename;
ENAME
SMITH
ALLEN
WARD
JONES
MARTIN
BLAKE
CLARK
SCOTT
KING
TURNER
ADAMS
JAMES
FORD
MILLER
14 rows selected.
SQL> exec :name := 'BLAKE'
PL/SQL procedure successfully completed.
SQL> select ename from emp where case when :name in ('SMITH','ALLEN') then ename
2 else :name end = ename;
ENAME
BLAKERgds. -
CASE WHEN functionality in BI Publisher
I have previously used Discoverer to do our reporting and am investigating the differences between the two products. I understand that its chalk and cheese but one thing I am having trouble identifying is the CASE WHEN functionality that we use Discoverer in BI Publisher.
An example of the usage for our CASE WHEN would be creating a derived column in a report to convert existing data into a more standardised format.
I imagine this is quite a simple answer and I have just missed it but could anyone out there help me with where I can input the functionality in BI publisher.
I am not the most technically gifted so any answers with simple words help :-)
Edited by: 943098 on 27-Jun-2012 03:25You can use CASE WHEN in a sql query in a data model. You can also use it in the RTF template via "if then else", choose statements etc
Take a look at section 4.10 in the BI publisher Report Designer's guide for use cases/examples: http://docs.oracle.com/cd/E23943_01/bi.1111/e22254.pdf
Thanks,
Bipuser -
How to use xsl document() function with LiveCycle XSLT processor
Hello,
I would like to use LiveCycle XSLT processor to merge xml documents by using the xsl document() function.
However, I have not, yet, found clear reference information on the specifics of how to accomplish in LC. For instance if you have
a transformation that does merging using a standalone xml editor (such as Oxygen), than what is required to accomplish the same
using the LiveCycle XSLT service. How do you specify the URI of the XML document that is specified as an input in the xsl document() function. Your insight is appreciated. RegardsHello Steve,
I checked the reference that you cited (XSLT Transformation). The reference omits discussing how to use xlst document() function within a stylesheet. I think that probably means that feature of xslt technology is not directly available through LiveCycle. When I find a workaround, I'll post an update...for the user community that might encounter the same issue. Thank you for your response and insight. Regards, jb1809 -
How to use the set functions effectively in webi ,please let me know with detail
how to use the set functions effectively in webi ,please let me know with detail
Hi,
we use use set functions on heirarchies with aggregate functions mostly .
If you include member_set, Min returns the minimum value of the aggregated data for all members in the member set.
Member_set can include multiple sets separated by semicolons (;).
The list of member sets must be enclosed in {}.
If the member set expression does not specify a precise member or node, the hierarchy referenced must be present in the table, then the member set expression references the current member in the hierarchy in the table. If the hierarchy is not in the table, the function returns the message #MULTIVALUE.
Eg .
1) Ancestor
=Sum([YTD] ; {Ancestor([Test Hierarchy];2)})
2) IsLeaf
=[Test Hierarchy].IsLeaf
You can use this function when you want to show your Measure only at lower level .
3) .Depth
=[Test Hierarchy].Depth
This is also function used with hierarchy to find Level of Members .
Follow this link for PDF reference .
Page 147
https://www.google.co.in/url?sa=t&rct=j&q=&esrc=s&source=web&cd=2&cad=rja&ved=0CDIQFjAB&url=https%3A%2F%2Fhelp.sap.com%2Fbusinessobject%2Fproduct_guides%2Fboexir4%2Fen%2Fxi4sp5_ffc_en.pdf&ei=nBAUU-iUM4WWrAeMuoCoDg&usg=AFQjCNHakXsEjd_yUk2y3lVdibf3PXpEOA&bvm=bv.61965928,d.bmk
search on SCN this question was discussed before also one those links .
http://scn.sap.com/thread/3183380
Hope this will help you . -
How to use Spell-check functionality for textbox (like Orkut, gtalk)
How to use Spell-check functionality for tex Hello Friends,
I am working on a JSP application. I wanted to add Spell check for text box like we have here, when we post a message. It automatically shows red line under the word, when ever spelling is wrong. Please tell me how I can do this. If possible, the code too.
Thanks.I believe the spell checking you see here, or on any other site, is the spell checking built into Firefox. At least that's what I see. Are you using Firefox?
-
How to use CASE statement in WDA
Hi All,
Can any one Please expain me ' How to use CASE statement in Web dynpro ABAP? '
Please give me an example also.
Thanks in Advance !Hi,
The usage of case statement in webdynpro is same as used in general ABAP.
Data: l_id type string.
l_id = wdevent->get_string( 'ID' ).
case l_id.
when 'BTN1'.
when 'BTN2'.
when 'OTHERS'.
endcase.
Regards,
Radhika. -
How to use CASE stmt in Where clause
Hi,
How to use CASE stmt in WHERE clause?. I need the code. Please send me as early as possible..........Hi,
1004977 wrote:
Hi,
How to use CASE stmt in WHERE clause?. There's no difference between how a CASE expression is used in a WHERE clause, and how it is used in any other clause. CASE ... END always returns a single scalar value, and it can be used almost anywere a single scalar expression (such as a column, a literal, a single-row function, a + operation, ...) can be used.
CASE expressions aren't needed in WHERE clauses very much. The reason CASE expressions are so useful is that they allow you to do IF-THEN-ELSE logic anywhere in SQL. The WHERE clause already allows you to do IF-THEN-ELSE logic, usually in a more convenient way.
I need the code.So do the peple who want t help you. Post a query where you'd like to use a CASE expression in the WHERE clause. Post CREATE TABLE and INSERT statements for any tables used unless they are commonly available, such as scott.emp). Also, post the results you want from that sample data, and explain how you get those resuts from that data.
See the forum FAQ {message:id=9360002}
Please send me as early as possible..........As mentioned bfore, that's rude. It's also self-defeating. Nobody will refuse to help you because you don't appear pushy enough, but some people will refuse to help you if you appear too pushy. -
Update multiple rows using CASE WHEN
I have the table ACCOUNT of structure as follow:
ACCOUNT_ID
ACCOUNT_STATUS
004460721
2
042056291
5
601272065
3
I need to update the three rows at once using one SELECT statement such that, the second column will be 5, 3, 2 respectively.
I used the following query but seems there is something missing
UPDATE ACCOUNT
SET ACCOUNT_STATUS = CASE
WHEN ACCOUNT_STATUS = '004460721' THEN 5
WHEN ACCOUNT_STATUS = '042056291' THEN 3
WHEN ACCOUNT_STATUS = '601272065' THEN 2
WHERE ACCOUNT_ID IN ('004460721','042056291','601272065')
My question, is this way correct? if no, can I use CASE WHEN statement and how or I only have choice of using SUB-SELECT to acheive that in one statement?Hi,
Hawk333 wrote:
I have the table ACCOUNT of structure as follow:
ACCOUNT_ID
ACCOUNT_STATUS
004460721
2
042056291
5
601272065
3
I need to update the three rows at once using one SELECT statement such that, the second column will be 5, 3, 2 respectively.
I used the following query but seems there is something missing
UPDATE ACCOUNT
SET ACCOUNT_STATUS = CASE
WHEN ACCOUNT_STATUS = '004460721' THEN 5
WHEN ACCOUNT_STATUS = '042056291' THEN 3
WHEN ACCOUNT_STATUS = '601272065' THEN 2
WHERE ACCOUNT_ID IN ('004460721','042056291','601272065')
My question, is this way correct? if no, can I use CASE WHEN statement and how or I only have choice of using SUB-SELECT to acheive that in one statement?
What happens when you try it?
Did you mean "WHEN ACCOUNT_ID = ..."?
A CASE expressions always needs an END keyword.
Depending on your requirements (that is, why are those rows being changed, and how do you determine the new values) a CASE expression in an UPDATE statement, similar to what you posted, could be a good way to do it. MERGE (instead of UPDATE) would also be an option, especially if you want to avoid updating rows that already happen to have the correct values. -
How to use 'several screen function' used to be in os x 10.6
hi ! ^^
how r u ? good !
how to use 'several screen function' used to be in os x 10.6 ??
it was possible to change whole screen with 'command + arrow keys' (option + arrow keys maybe ??)
but, in os x 10.7, it seems it is not possible. and instread of it 'mission controls' that is not uesful ..
no windows drive direct access. no several screen function. crash when control panel ask me administration right.
os x 10.5 or 10.4 was much easy to control.
plz fix and add good functions of 10.6 , remove good functions is not called 'upgrade'.You can still do it with CONTROL + Arrow keys, the same as 10.6
Regards,
Captfred -
Who can tell me how to use ni-imaq functions imgSessionSerialFlash,imgSessionSerialWrite and imgSessionSerialRead to set and get my carema attribute?
My camera is duncantech ms3100 and the frame grabber is pci-1428.I use ni-imaq2.6.When I use these functions,it tell me error -1074397163(IMG_ERR_BINT:Bad interface) .I have the same problem on my IPAD 2. One calender that i cant delete or find any settings for... Its just in the calender app under diffrent calenders. how do i delete it?
Maybe you are looking for
-
More than one slideshow in iDVD?
I have just finished creating a slideshow & imported it to iDVD as my new project. However, now I want to make another one. I want to know if it is possible for me to add another slideshow to the same iDVD project or I have to make it as a separate o
-
How can I use Automator to search only in folders whose name contains a certain word?
I'm very new to Automator. What I am trying to accomplish is this: I am using Transmit as my FTP client. I have mounted a server as a disk to my desktop. I am using Automator to try and search this server and open files whose path contains the word "
-
Hi. I've recently bought a new computer that doesn't have a CD drive. I am trying to install Dreamweaver CS4 on my new computer (and uninstall from they old one), but I only have the program on CD. Is it possible for me to download Dreamweaver CS4 an
-
Best Practice for Release prerequisites in POs
Hello... Do you know a link, or document which explain the way of work of the release prerequisites in POs ?? I know the rest of the setting regarding of the release procedure, the only concern I have is how works the prerequisites Hope you have a m
-
Difference in using the same component made in mxml or action-script
Hi, I made a sample project to show a kind of bug in the SuperTabNavigator component of FlexLib In this sample you can see that using the same component (made in both mxml or action-script) can make a difference I'm just wondering why ? Thanks Here i