Database learning #1


Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

declare @t table(Customer_ID int, start_interval int, end_interval int)
    declare @start_date datetime, @end_date datetime
    declare @weekMin int, @dayMin int,@hourMin int
    set @hourMin = 60
    set @dayMin = @hourMin*24
    set @weekMin = @dayMin*7
    set @start_date='1990-01-01 00:00'
    declare @interval_s1 int, @interval_f1 int;
    -- carsamba 18:30 carsamba 20:00
    set @interval_s1= @dayMin*2+@hourMin*18+30
    set @interval_f1= @dayMin*2+@hourMin*20+0
    declare @interval_s2 int, @interval_f2 int;
    -- sali 09:30 carsamba 23:50
    set @interval_s2= @dayMin*1+@hourMin*9+30
    set @interval_f2= @dayMin*2+@hourMin*23+50
    insert @t values(1 ,@interval_s1,@interval_f1) 
     insert @t values(2 ,@interval_s2,@interval_f2) 

    select * from @t
    --select * from @t where DATENAME(dw, StartDateTime) = 'Sunday' OR DATENAME(dw, StartDateTime) = 'Friday'
    declare @curr_time datetime, @curr_time_inmins int, @rem int
    set @curr_time='2012-07-26 20:14'
    set @curr_time_inmins = DATEDIFF(minute, @start_date,@curr_time)
    select @curr_time_inmins
    set @rem = @weekMin%@curr_time_inmins
    select @rem
    set @end_date='2010-02-11'
    select DATENAME(weekday, @start_date)
    SELECT DATEDIFF(minute, @start_date,@end_date)
    select @hourMin 'hourmin'
    select @dayMin
    select @weekMin

Enter Parameters

Switch to meta site
loading Hold tight while we fetch your results