2012年12月17日 星期一

[SQL] 判斷日期


Dim str As String = "select * from [A010詢價單資料表-表頭] Where 1=1"

'選擇哪個查詢條件
Select Case frm詢價單search.TabControl1.SelectedIndex
     Case 0 '一般
            'SELECT         外調單號, 預訂交期
            'FROM             E010外調訂單資料表明細
            'WHERE         (DATEPART(yy, 預訂交期) = 2008) AND (DATEPART(mm, 預訂交期) = 8)
            'ORDER BY  預訂交期

      If frm詢價單search.TextBox1.Text <> "0" Then
          '日期-年度
           str = str + " and DATEPART(yy,日期) = " & _
           frm詢價單search.TextBox1.Text.ToString & ""
      End If

      If frm詢價單search.ComboBox1.Text <> "0(全部)" Then
            '日期-月份
             str = str + " and DATEPART(mm,日期) = " & _
             Microsoft.VisualBasic.Left(frm詢價單search.ComboBox1.Text, 2) & ""
      End If

........

參考:
MS-SQL時間格式一覽
MS SQL日期處理方法
MSSQL 抓取現在日期的函數
善用 SQL Server 中的 CONVERT 函數處理日期字串
SQL Server中使用convert转化长日期为短日期
sql使用convert转化长日期为短日期的总结
MS SQL 的datetime 格式轉換
MS SQL日期處理方法-整理(Date and Time Functions Tips)
SQL Server datetime LIKE select?
sql的between與查詢日期範圍
SQL between 日期范围
找出某個日期區間內的資料
各種日期時間計算
日期相減, 算出天數
計算日期的天數
計算兩個日期差距幾天
日期運算的小技巧整理(以起迄日期結束日期為例)
如何下日期相減後得到的是日期
SQL 日期的應用
在SQL中 得到日期 並格式化

TIPS-.NET DateTime Formating
Linq小技巧:日期處理

其它(日期)參考:
時間格式及方法運用
標準日期和時間格式字串
DateTime.GetDateTimeFormats 方法
DateTimeFormatInfo 類別
用DateTimeFormatInfo格式化日期时间(C#)
AM and PM with "Convert.ToDateTime(string)"
how get a.m. p.m. from DateTime?
自訂日期和時間格式字串
datetime.now first and last minutes of the day
SQL时间类型(DateTime)模糊查询及Between
善用 SQL Server 中的 CONVERT 函數處理日期字串
[SQL]使用BETWEEN要注意的地方
[筆記] SQL - between

沒有留言:

張貼留言