久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何僅與月份和年份進行比較,而不是完整日期

How do I do a comparison with just a month and year, not a complete date?(如何僅與月份和年份進行比較,而不是完整日期?)
本文介紹了如何僅與月份和年份進行比較,而不是完整日期?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我需要編寫一個存儲過程來允許某人搜索數據庫.但是,我得到的只是月份和年份的整數.數據庫有月份和年份字段.但我不知道如何設置比較.

I need to write a stored procedure to allow someone to search a db. However, all I get are ints for month and year. And the db has month and year fields. But I can't figure out how to set up the comparison.

例如:我得到 2008 年 3 月和 2010 年 6 月.

Ex: I get March 2008 and June 2010.

我需要在數據庫中搜索日期(由月份和年份字段指定)在這兩個日期之間的記錄.

I need to searhc the database for records where the date, as specified by the month and year fields, are between thoese two dates.

編輯

給定兩個 Date 輸入,我如何找到落在這些日期之間的所有記錄?每條記錄只有代表年和月的整數.

Given two Date inputs, how do I find all records that fall between those dates? Each record only has integers representing year and month.

推薦答案

假設您在 SQL Server 中提供了名為 @StartDate 和 @EndDate 的日期變量:

Assuming you are provided Date variables called @StartDate and @EndDate in SQL Server:

SELECT
  *
FROM
  MyTable
WHERE  
  -- yields "200901 between 200801 and 201104" on inputs 01-01-2008, 04-01-2011
  Convert(VarChar(10), MyTable.Year) + Replace(Str(MyTable.Month, 2), ' ', '0')
   BETWEEN
  Convert(VarChar(10), YEAR(@StartDate)) + Replace(Str(MONTH(@StartDate), 2), ' ', '0')
   AND
  Convert(VarChar(10), YEAR(@EndDate)) + Replace(Str(MONTH(@EndDate), 2), ' ', '0')

參考資料

  • 簡單用于 Int 到字符串轉換的左填充 - 受啟發的 Replace(Str(MyTable.Month, 2), ' ' , '0')
  • TSQL 之間
  • Simple Left-Padding for Int to String Conversion - Inspired Replace(Str(MyTable.Month, 2), ' ' , '0')
  • TSQL Between

這篇關于如何僅與月份和年份進行比較,而不是完整日期?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Converting Every Child Tags in to a Single Column with multiple Delimiters -SQL Server (3)(將每個子標記轉換為具有多個分隔符的單列-SQL Server (3))
How can I create a view from more than one table?(如何從多個表創建視圖?)
Create calculated value based on calculated value inside previous row(根據前一行內的計算值創建計算值)
How do I stack the first two columns of a table into a single column, but also pair third column with the first column only?(如何將表格的前兩列堆疊成一列,但也僅將第三列與第一列配對?) - IT屋-程序員軟件開發技
Recursive t-sql query(遞歸 t-sql 查詢)
Convert Month Name to Date / Month Number (Combinations of Questions amp; Answers)(將月份名稱轉換為日期/月份編號(問題和答案的組合))
主站蜘蛛池模板: 成人自拍视频 | 亚洲精品在线免费观看视频 | 国产高清精品网站 | 福利一区二区 | av毛片 | 久久久91精品国产一区二区三区 | 午夜免费在线观看 | 欧美性吧 | 国产综合视频 | 日本一区二区电影 | 久久精品亚洲精品 | 亚洲男人天堂网 | 久久99精品久久久久久国产越南 | 喷水毛片 | 麻豆91精品91久久久 | 久久综合久久自在自线精品自 | 午夜欧美a级理论片915影院 | 91久久| 亚洲网在线 | 国产91在线播放 | 色综合激情 | 天天碰日日操 | 成人国产精品久久 | 久久久久国产 | 日韩精品一区二区三区免费视频 | 超碰成人免费 | www.精品国产 | 毛片毛片毛片毛片 | 精品欧美一区免费观看α√ | 成人在线免费 | 欧美精品福利 | 狠狠爱视频 | 久久与欧美| 91国产在线播放 | 国产欧美精品一区二区三区 | 久久久久久91 | 99re在线视频 | 天天操天天射天天舔 | 日韩亚洲欧美综合 | 亚洲国产成人在线观看 | 国产区在线|