--创建表
CREATE TABLE [dbo].[WeekendDate](
[ID] [int] IDENTITY(1,1) NOT NULL,
[Date] [datetime] NULL,
[Weekday] [nvarchar](50) COLLATE Latin1_General_CI_AS NULL
) ON [PRIMARY]
--将周六日的数据插入到表
declare @datetime datetime,@weekday char(12)
set @datetime='2012-01-01'
while @datetime<='2017-01-01'
begin
select @weekday=datename(weekday,@datetime)
if @weekday= 'Saturday' insert WeekendDate([date],[weekday]) values(@datetime,@weekday)
if @weekday= 'Sunday' insert WeekendDate([date],[weekday]) values(@datetime,@weekday)
--select @datetime,@weekday
select @datetime=dateadd(day,1,@datetime)
end
--select * from weekenddate