Solved

Sybase command doubt

Posted on 2012-03-12
4
623 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Database tuning – How to start and what to tune. This question is frequently asked by many people, both online and offline. There is no hard and fast rule-of-thumb for performance tuning, however, before beginning the tuning process one should a…
Read about achieving the basic levels of HRIS security in the workplace.
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now