SQL Server CE –Use functions
Posted: March 10, 2014 Filed under: Uncategorized Leave a commentYou 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