Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Sybase command doubt

Posted on 2012-03-12
4
Medium Priority
?
635 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 1000 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 1000 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
Creating a Cordova application which allow user to save to/load from his Dropbox account the application database.
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…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Suggested Courses

916 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