SQL Server CE –Use functions


You can calculate a number of hours in decimal format to Hours and minutes. The following is to present the result to hours and closest 15 minutes intervals.

Since SQL Server CE supports CASE, CAST , Mod for Int, you can try below query:



SELECT   dt,  
CAST (Cast((dt*60)/60 as int) 
+ CASE WHEN ((cast((dt*60) as INT)%60)/15 + (CASE WHEN (cast((dt*60) as INT)%60)%15>7.5 Then 1 Else 0 End) )=4 Then 1 Else 0 End as Nvarchar(5)) +' Hours' 
+ ' and ' + Cast ( ((cast((dt*60) as INT)%60)/15 + (CASE WHEN (cast((dt*60) as INT)%60)%15>7.5 Then 1 Else 0 End) )*15%60 as Nvarchar(5))  + ' Minutes'
AS HoursAndMinutes
FROM test1


 
Advertisements


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s