Database learning #1

0

Please login or register to vote for this query.

(click on this box to dismiss)

Moderators

Q&A for community managers, administrators, and moderators

SET NOCOUNT ON
    GO
  
  declare @t table(id int, baslangic datetime, bitis datetime, tekrar bit, gunluk bit, aralik_bas int, aralik_son int,zaman_id int)
    
    INSERT INTO @t VALUES (63, '2012-6-26 11:35:57', '2013-12-30 23:59:00', 1, 0, 1000, 8000, 1);
    INSERT INTO @t VALUES (16, '2012-6-5 11:44:15', '2013-12-30 23:59:00', 1, 0, 2010, 4310, 2);
    INSERT INTO @t VALUES (12, '2012-5-29 11:46:03', '2013-12-30 23:59:00', 1, 1, 565, 895, 3);
    
    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'
    
    --select * from @t
    
    declare @curr_time datetime, @curr_time_inmins int, @remWeek int, @remDay int
    set @curr_time='2012-07-04 19:30'
    set @curr_time_inmins = DATEDIFF(minute, @start_date,@curr_time)
    set @remWeek = @curr_time_inmins%@weekMin
    set @remDay = @curr_time_inmins%@dayMin
    
    /*select DISTINCT * from @t where (@remWeek>=start_interval AND @remWeek<=end_interval AND week_or_day='week') OR
    (@remDay>=start_interval AND @remDay<=end_interval AND week_or_day='day')    */
    
    SELECT * FROM @t WHERE @remWeek<aralik_son AND gunluk=1
      
    /*
    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 to meta site
loading Hold tight while we fetch your results