Solved

Sybase command doubt

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
constraint check 2 48
Multiple MSSQL instances on same server 4 47
ORA-02288: invalid OPEN mode 2 57
Postgresql: Import csv constant errors, how to fix? 9 65
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…
As technology users and professionals, we’re always learning. Our universal interest in advancing our knowledge of the trade is unmatched by most industries. It’s a curiosity that makes sense, given the climate of change. Within that, there lies a…
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…

860 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