Database learning #1

0

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

SET NOCOUNT ON
    GO
  
  declare @t table(Customer_ID int, start_interval int, end_interval int, week_or_day varchar(6))
    
    
    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,'week') 
    insert @t values(2 ,@interval_s2,@interval_f2,'week')
    insert @t values(2 ,@interval_s2,@interval_f2,'week')

    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-03 20:14'
    set @curr_time_inmins = DATEDIFF(minute, @start_date,@curr_time)
    select @curr_time_inmins
    set @rem = @curr_time_inmins%@weekMin
    select @rem
    select DISTINCT * from @t where @rem>start_interval AND @rem<end_interval AND week_or_day='week'
        
    /*
    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
    
    
  DECLARE @x INT
  */

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results