time表日期新增

BI中,最重要的分析方式就是時間序列了,所以少不了日期的成倍新增。
代碼如下:

 Dim date1 As String = "2008-07-08"
        
Dim the_date As Date '=  ' = Date.Now.ToShortDateString
        Dim i As Int16 = 0
        
For i = 0 To 365
            the_date 
= CDate(date1).AddDays(i)

            mysql 
= "INSERT INTO dbo.Time_by_day ( The_Date, The_Year, The_Month, The_Day)"
            mysql 
&= " VALUES (@The_Date, @The_Year, @The_Month, @The_Day)"

            sqlcomm(mysql.Trim)
            mycomm.Parameters.AddWithValue(
"@The_Date", the_date)
            mycomm.Parameters.AddWithValue(
"@The_Year"Year(the_date))

            mycomm.Parameters.AddWithValue(
"@The_Day"Day(the_date))
            mycomm.Parameters.AddWithValue(
"@The_Month"Month(the_date))

            
Try
                conn.sqlconn_Open()
                mycomm.ExecuteNonQuery()
                conn.sqlconn_Close()
                
Me.Label1.Text &= "傳送成功!!"
            
Catch ex As Exception
                
Me.Label1.Text &= "出錯了:" + ex.Message
            
End Try
        
Next

然後在查詢分析器執行
update Time_by_day set the_year=year(the_date),the_month=month(the_date),
the_quarter
=DATEPART(qq,the_date),the_week=DATEPART(wk,the_date),the_day=day(the_date)
其實可以一起操作的,但是我沒找到.net相關季度和星期的函數,所以。。。
posted @ 2006-07-08 14:40  Nina  阅读(488)  评论(1)    收藏  举报