熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> SQL語言 >> 正文

初學者必讀:精講SQL中的時間計算語句[2]

2022-06-13   來源: SQL語言 

  請問這個語句應該怎麼去寫?

  答 if object_id(tablename) is not null drop table tablename
  select as time_id as time_date as [year] as week_of_year 星期日 as [day]
  into tablename
  union select 星期一
  union select 星期二
  
  select time_id time_date [year] + cast(week_of_year as varchar()) + 周(
  + cast(month(week_begin) as varchar()) + / + cast(day(week_begin) as varchar()) +
  + cast(month(week_end) as varchar()) + / + cast(day(week_end) as varchar()) as week_of_year
  from (select * dateadd(day datepart(weekday time_date) time_date) as week_begin
  dateadd(day datepart(weekday time_date) time_date) as week_end from tablename) a
  /*
  time_id time_date year week_of_year
   周(//)
   周(//)
   周(//)
  */
  
  drop table tablename

[]  []  []  []  []  


From:http://tw.wingwit.com/Article/program/SQL/201311/16172.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.