Solved

Sybase command doubt

Posted on 2012-03-12
4
628 Views
Last Modified: 2012-03-13
Hi Experts...

I have a sybase quesry as shown which gives the resultant as :315.
Can anyone explain how this result is achieved.

Query:
select ( ((datepart(hh,'5:28:31') * 60) + datepart(mi,'5:28:31'))/15)*15

Result:
315
Please help...
0
Comment
Question by:gaugeta
  • 2
4 Comments
 
LVL 12

Expert Comment

by:Sharon Seth
ID: 37710255
datepart(hh,'5:28:31')   returns the hour part i.e 5
datepart(mi,'5:28:31')   returns the minute part , which is 28

hh and mi are predefined constants in sybase
0
 
LVL 14

Assisted Solution

by:Jan_Franek
Jan_Franek earned 250 total points
ID: 37710305
datepart(hh,'5:28:31') = 5
(datepart(hh,'5:28:31') * 60) = 300
datepart(mi,'5:28:31') = 28
((datepart(hh,'5:28:31') * 60) + datepart(mi,'5:28:31')) = 328
((datepart(hh,'5:28:31') * 60) + datepart(mi,'5:28:31'))/15 = 328/15 = 21 - this is little strange, but as both arguments are integer, the division result is also truncated to integer

and in the end 21 * 15 = 315
0
 

Author Comment

by:gaugeta
ID: 37710315
@sharonseth:Thanks for the reply.
Is select(datepart(mi,'5:28:31'))/15)*15 where the resultant i s1.8666 is it rounded off to 1 so the resultant is 300+15.
Please clarify.
0
 
LVL 12

Accepted Solution

by:
Sharon Seth earned 250 total points
ID: 37710464
That would be same as select ((300 + 28)/15)*15

328/15 = 21.866

Decimal part is dropped
so , 21 * 15 = 315
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

SQL Command Tool comes with APEX under SQL Workshop. It helps us to make changes on the database directly using a graphical user interface. This helps us writing any SQL/ PLSQL queries and execute it on the database and we can create any database ob…
CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question