2011-04-12 38 views

回答

2

使用一個明確的日期格式,如'2010-08-04'。這種排序方式無論是日期還是文本,每個人都知道它意味着4月8日,而不是4月8日。

我喜歡用calendar table這樣的查詢。這將選擇日期。

select cal_date 
from calendar 
where cal_date between '2010-08-04' and '2011-08-04' 
and (day_of_week = 'Sat' or day_of_week = 'Sun'); 

像這樣的東西會將它們插入到表中。 (根據表格而定)

insert into your_table_name 
select cal_date 
from calendar 
where cal_date between '2010-08-04' and '2011-08-04' 
and (day_of_week = 'Sat' or day_of_week = 'Sun'); 
+2

大家都知道它是04年8月4日,除了SQL Server,這將返回4這個查詢:'設置語言英國 選擇DATEPART(月,CONVERT(datetime,'2010-08 -04' ))'。用於轉換爲日期時間的明確的僅限日期的格式不包括組件之間的破折號,例如, ''20100804'' – 2011-04-12 10:48:53

+0

@Damien_The_Unbeliever:你說得對。格式'yyyy-mm-dd'只是SQL標準。 – 2011-04-12 11:18:52

相關問題