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

將月份名稱轉換為日期/月份編號(問題和答案的組

Convert Month Name to Date / Month Number (Combinations of Questions amp; Answers)(將月份名稱轉換為日期/月份編號(問題和答案的組合))
本文介紹了將月份名稱轉換為日期/月份編號(問題和答案的組合)的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我看了很多回答我的問題,但沒有一個真正回答我的問題.

I had a look at numerous answer to my question, but none really answered my question.

我有數據:

cBatchDesc  idBatches
Journal Batch - March 2017  88
Journal Batch - April 2017  2
Journal Batch - May 2017    3
Journal Batch - June 2017   4
Journal Batch - July 2017   5
Journal Batch - August 2017 6
Journal Batch - September 2017  7
Journal Batch - October 2017    8
Journal Batch - November 2017   9
Journal Batch - December 2017   10
Journal Batch - January 2018    11
Journal Batch - February 2018   12
Journal Batch - March 2017  89
Journal Batch - April 2017  13
Journal Batch - May 2017    14
Journal Batch - June 2017   15
Journal Batch - July 2017   16
Journal Batch - August 2017 17
Journal Batch - September 2017  18
Journal Batch - October 2017    19
Journal Batch - November 2017   20
Journal Batch - December 2017   21
Journal Batch - January 2018    22
Journal Batch - February 2018   23
Journal Batch - March 2017  90
Journal Batch - April 2017  27
Journal Batch - May 2017    28
Journal Batch - June 2017   29
Journal Batch - July 2017   30
Journal Batch - August 2017 31
Journal Batch - September 2017  32
Journal Batch - October 2017    33
Journal Batch - November 2017   34
Journal Batch - December 2017   35
Journal Batch - January 2018    36
Journal Batch - February 2018   37

我需要將 cBatchDesc 末尾的日期名稱轉換為實際日期.

I needed to convert the date name at the end of cBatchDesc to the Actual Date.

推薦答案

首先,如果您發布的數據是易于使用的",例如以下內容,人們會更愿意提供幫助...

First of all, people would be a whole lot more willing to help if the data you post is "Readily Consumable", like the following...

   DROP TABLE IF EXISTS #TestTable;
GO
 SELECT  v.cBatchDesc, v.idBatches
   INTO #TestTable
   FROM (VALUES  
         ('Journal Batch - March 2017'    ,88)
        ,('Journal Batch - April 2017'    ,2 )
        ,('Journal Batch - May 2017'      ,3 )
        ,('Journal Batch - June 2017'     ,4 )
        ,('Journal Batch - July 2017'     ,5 )
        ,('Journal Batch - August 2017'   ,6 )
        ,('Journal Batch - September 2017',7 )
        ,('Journal Batch - October 2017'  ,8 )
        ,('Journal Batch - November 2017' ,9 )
        ,('Journal Batch - December 2017' ,10)
        ,('Journal Batch - January 2018'  ,11)
        ,('Journal Batch - February 2018' ,12)
        ,('Journal Batch - March 2017'    ,89)
        ,('Journal Batch - April 2017'    ,13)
        ,('Journal Batch - May 2017'      ,14)
        ,('Journal Batch - June 2017'     ,15)
        ,('Journal Batch - July 2017'     ,16)
        ,('Journal Batch - August 2017'   ,17)
        ,('Journal Batch - September 2017',18)
        ,('Journal Batch - October 2017'  ,19)
        ,('Journal Batch - November 2017' ,20)
        ,('Journal Batch - December 2017' ,21)
        ,('Journal Batch - January 2018'  ,22)
        ,('Journal Batch - February 2018' ,23)
        ,('Journal Batch - March 2017'    ,90)
        ,('Journal Batch - April 2017'    ,27)
        ,('Journal Batch - May 2017'      ,28)
        ,('Journal Batch - June 2017'     ,29)
        ,('Journal Batch - July 2017'     ,30)
        ,('Journal Batch - August 2017'   ,31)
        ,('Journal Batch - September 2017',32)
        ,('Journal Batch - October 2017'  ,33)
        ,('Journal Batch - November 2017' ,34)
        ,('Journal Batch - December 2017' ,35)
        ,('Journal Batch - January 2018'  ,36)
        ,('Journal Batch - February 2018' ,37)
        )v(cBatchDesc,idBatches)
;

我很高興你自己解決了這個問題,但你可以通過計算-"的位置來讓事情變得更靈活一些.這樣您就可以處理其他描述(如果發生).

I'm glad you solved it on your own but you can make things a little more flexible by calculating the position of the "-" so you can handle other descriptions, should they occur.

此外,您可以干燥"(D不要R重復Y我們自己)您的代碼(以便更容易閱讀/更改)只需計算一次日期對于每一行使用這樣的 CROSS APPLY(請注意,您沒有提供 cBatchNo 列,因此 ORDER BY 不同,我沒有顯示 SUBSTRING)...

Also, you can "DRY" (Don't Repeat Yourself) your code out (to make it easier to read/change) by calculating the date just once for each row using a CROSS APPLY like this (note that you didn't provide a cBatchNo column so the ORDER BY is different and I didn't display the SUBSTRING)...

 SELECT  cBatchDesc
        ,MonthNumber = DATEPART(mm,ca.Date)
        ,MonthStart  = ca.Date
        ,MonthEnd    = EOMONTH(ca.Date)
        ,idBatches
   FROM #TestTable
  CROSS APPLY (SELECT CONVERT(DATE,SUBSTRING(cBatchDesc,CHARINDEX('-',cBatchDesc)+1,100)))ca(Date)
  ORDER BY ca.Date, idBatches
;

對于您提供的數據,提供以下(截斷的)結果......

For the data you provided, that provides the following (truncated) results ...

這篇關于將月份名稱轉換為日期/月份編號(問題和答案的組合)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 查詢)
Join instead of correlated subquery(加入而不是相關子查詢)
主站蜘蛛池模板: 成人精品一区二区三区 | 久久中文网 | 黄色免费在线观看网址 | 人人澡视频 | 中文字幕精品一区 | 999久久久久久久久6666 | 色婷婷婷婷色 | 男女啪啪高潮无遮挡免费动态 | 黄视频在线网站 | 成人av高清 | 亚洲欧洲日韩精品 中文字幕 | 精品欧美一区二区三区久久久 | 国产激情视频在线观看 | 免费观看黄a一级视频 | 久久久女女女女999久久 | 美女天天干 | 国产一区二区激情视频 | 精品欧美色视频网站在线观看 | 最新中文字幕在线 | 日韩中文字幕一区二区 | 一区在线观看 | 亚洲综合色自拍一区 | 亚洲精品视频在线看 | 黄色片视频 | 久久精品网 | www.一区二区三区 | 国产高清视频在线观看 | 国产高清av免费观看 | 在线观看国产视频 | 欧美一级在线视频 | 日韩激情在线 | 亚洲欧洲成人 | 91国在线高清视频 | 精品国产一区二区三区av片 | 激情网站在线观看 | 日韩在线精品 | 成人在线播放网站 | 久久久久国产 | 欧美在线一区视频 | 国产精品www | 夜夜精品浪潮av一区二区三区 |