Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 months ago.
Improve this question
SIGN(FLOOR((X.RT - O.RD) * 24 * 60) - 2) >= 0
What does SIGN and FLOOR means here? Also can someone explain what is DEVCAT ?
Thanks!
You can look all these functions up in the Oracle documentation for single-row numeric functions.
FLOOR returns the largest integer equal to or less than n.
SIGN returns the sign of n.
For value of NUMBER type, the sign is:
-1 if n<0
0 if n=0
1 if n>0
SIGN(FLOOR((X.RT - O.RD) * 24 * 60) - 2) >= 0
Guessing from your magic numbers, X.RT and O.RD would be dates and you are calculating the number of days difference between the two values then multiplying by 24 to give hours and 60 to give minutes and then round down and subtract 2 minutes and check if the sign is 0 or positive.
It could be more simply written as:
x.RT - INTERVAL '2' MINUTE >= o.RD
db<>fiddle here
"DEVCAT" does not appear in the Oracle documentation so without more context its meaning is unknown.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I have a field with sales_start_date( values like 2014-06-17 ,2015-07-23...)
I need to do calculation based on sales_start date..
I have to take the most recent month-end date(i have to force this value to 2016-07-31) and subtract the sale_start_date to get an integer count of the days elapsed. If number of days passed is less than 2 default the value 2
sales_start_date
2016-01-01
2016-07-30
Output
Calculated field
155
2
Can any one help me in writing case statement.
Your help is much appreciated.
Thank You,
Swathi.
You basically need to use DATEDIFF
SELECT DATEDIFF(day,<enter start date column here>,<most recent month-end date column here>) AS [Calculated field]
FROM <your table here>
SQL-server 2012 + you have the EOMONTH() to help you get to the end of the month more easily.
;WITH cteData AS (
SELECT CAST('2016-01-01' AS DATE) as Start_date
UNION ALL
SELECT '2016-07-30'
)
SELECT
EOMONTH(DATEADD(MONTH,-1,GETDATE())) as EndOfPreviousMonth
,DATEDIFF(DAY,Start_date,EOMONTH(DATEADD(MONTH,-1,GETDATE()))) + 1 as DaysDifferent
FROM
cteData
This question already has answers here:
SQL Server Strange Ceiling() behavior
(2 answers)
Closed 8 years ago.
I've found a really weird behavior in SQL Server 2012, the CEILING of 100 gives me 101 and sometimes 100.
I need to get the ceiling of a number considering 2 decimals, that means convert a 0.254 to 0.26
So I tried to run
SELECT CEILING(field * 100.0) / 100.0
FROM Table
This should work, and it does, at least for most of the data.
Any idea on how to solve it?
What you are seeing here is floating point errors. When you store a number in a floating point column, it isn't exact, so the number 1 may actually be 1.0000000000000000000000001. So multiplying it by 100 gives you a number a tiny bit greater than 100, hence CEILING rounds it up to 101.
The solution is to ROUND the number first which will remove the floating point errors. Note I have used 5 as the number of decimal places, you will need to decide on your own value of precision.
SELECT CEILING(ROUND(field,5)*100.0)/100.0 FROM Table
This question already has answers here:
Rounding a number to the nearest 5 or 10 or X
(13 answers)
Closed 8 years ago.
I need to round down a number to nearest hundred like these:
For example:
54678 become 54600
54611 become 54600
54699 become 54600
Any idea? thanks!
Here you can find the code basics for the RoundDown command which allows you to round numbers up to a certain number of digits.
What you need to do is basically for example divide your number by 100, then round them and again multiply by 100. It's an easy workaround... but should work!
If you don't want 54699 to become 54700, but just want it to be 54600, there is an easy solution.
If the number is stored as an integer (no decimal point), just divide it by 100, then multiply it by 100 again
If it is not stored as an integer, you will need to divide it by 100, cast it to an integer and then multiply it by 100
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 8 years ago.
Improve this question
Is there any oracle sql function which will help in presenting time as currently i am summing up the time for a column and calculating it in hours.
Time
892.26 (in hours)
requirement
Time (in same column) 892 hrs 26 min
Please suggest what can be done.
Perhaps you should reconsider the data model. If you store the time as number like 893.26 and treat it as 892 hours and 26 minutes, every calculation will be complicated.
You'd better to store the value as minutes only, like 53,546 (minutes), which come from the simple calculation, 893 x 60 + 26. Then you can add or subtract between the values simply by + or - and you can represent it as hours and minutes by simple calculation:
hours = trunc(value / 60)
minutes = mod(value, 60)
This can be done within your SQL:
select trunc(value / 60) || ' hrs ' || mod(value, 60) || 'min'
from ...
If your smallest tick is second, you should store every values in second. This can make things much more simple than the way you're using now.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a query in which I am calculating time. I want to make time double so that if the time is 01:40 then it should become 03:20. Here is my current query
SELECT TO_CHAR(TRUNC((ATN_INN-ACT_INN)*24),'09')||':'||
TO_CHAR(TRUNC(((ATN_INN-ACT_INN)*24-TRUNC((ATN_INN-ACT_INN)*24))*60),'09') B
FROM SML.EMP_INFO A
How should I go about this?
If you really what to work only with the time element, the easiest way to so is to employ the 'SSSSS' date mask, which returns the number of seconds after midnight. So this query will return double the number of seconds between the two columns:
select ( to_number(to_char(atn_inn, 'sssss'))
- to_number(to_char(acn_inn, 'sssss')) ) * 2 as double_diff_in secs
from sml.emp_info
/
Converting seconds into hours and minutes is left as an exercise for the reader.
Note that this query only makes sense if ATN_INN is later than ACT_INN but still on the same day. This is the clarification #Ben was trying to make (with no success). If this is not the case a different solution is required, something like ....
select ( ( extract ( hour from diff ) * 60)
+ extract ( minute from diff ) ) *2 as double_diff_in mins
from ( select to_dsinterval ( atn_inn - act_inn ) as diff
from sml.emp_info )
/
This returns the doubled different in minutes. Again, rendering the output into a display format is left to the reader.
It seems to me you are using the method described here (Subtraction between dates): http://www.akadia.com/services/ora_date_time.html
If you want to double the lenght of the period, you really only need to multiply the base time difference with 2, like this:
SELECT TO_CHAR(TRUNC((2*(ATN_INN-ACT_INN))*24),'09')
|| ':' ||
TO_CHAR(TRUNC(((2*(ATN_INN-ACT_INN))*24
-TRUNC((2*(ATN_INN-ACT_INN))*24))*60),'09') B
FROM SML.EMP_INFO A
This will give you the hour part and the minutes part of your results, you will probably want to have the days part too.