--也許有了這張表,你的工作會輕鬆很多!
create table [dbo].[time_dimension] (
[time_id] [int] identity (1, 1) not null ,
[the_date] [datetime] null ,
[the_day] [nvarchar] (15) null ,
[the_month] [nvarchar] (15) null ,
[the_year] [**allint] null ,
[day_of_month] [**allint] null ,
[week_of_year] [**allint] null ,
[month_of_year] [**allint] null ,
[quarter] [nvarchar] (2) null ,
[fiscal_period] [nvarchar] (20) null
) on [primary]
declare @weekstring varchar(12),
@ddate **alldatetime,
@**onth varchar(20),
@iyear **allint,
@idayofmonth **allint,
@iweekofyear **allint,
@imonthofyear **allint,
@squarter varchar(2),
@ssql varchar(100),
@adddays int
select @adddays = 1 --日期增量(可以自由設定)
select @ddate = '01/01/2002' --開始日期
while @ddate < '12/31/2004' --結束日期
begin
select @weekstring = datename (dw, @ddate)
select @**onth=datename(mm,@ddate)
select @iyear= datename (yy, @ddate)
select @idayofmonth=datename (dd, @ddate)
select @iweekofyear= datename (week, @ddate)
select @imonthofyear=datepart(month, @ddate)
select @squarter = 'q' + cast(datename (quarter, @ddate)as varchar(1))
insert into time_dimension(the_date, the_day, the_month, the_year,
day_of_month,
week_of_year, month_of_year, quarter) values
(@ddate, @weekstring, @**onth, @iyear, @idayofmonth, @iweekofyear,
@imonthofyear, @squarter)
select @ddate = @ddate + @adddays
end
go
select * from time_dimension
引用自:http://topic.csdn.net/t/20031226/23/2607995.html
讓資料庫產生一張詳細的日曆表
也許有了這張表,你的工作會輕鬆很多!create table dbo time dimension time id int identity 1,1 not null the date datetime null the day nvarchar 15 null the month nvarchar...
資料庫將一張表插入另一張表中
1.將一張表的資料插入到另一張表中 insert into seckill hjh id,code,name,drumbeating,strat time,productid,price,amount,pay time,num once,note,statu,cause,userid,check u...
MySQL 資料庫恢復一張表中的資料
如果使用 mysqldump uroot p123 user test.sql備份了user資料庫中的所有資料,但是當前只想要恢復該資料庫的某張表資料,該怎麼處理呢?已知恢復整個資料庫可以使用命令 mysql uroot p123 user test.sql 如果只恢復某一張表 1 新建乙個資料庫 ...