pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

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

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(加入而不是相關子查詢)
主站蜘蛛池模板: 上海租车公司_上海包车_奔驰租赁_上海商务租车_上海谐焕租车 | 自进式锚杆-自钻式中空注浆锚杆-洛阳恒诺锚固锚杆生产厂家 | 多米诺-多米诺世界纪录团队-多米诺世界-多米诺团队培训-多米诺公关活动-多米诺创意广告-多米诺大型表演-多米诺专业赛事 | 机构创新组合设计实验台_液压实验台_气动实训台-戴育教仪厂 | 永嘉县奥阳陶瓷阀门有限公司| 万烁建筑设计院-建筑设计公司加盟,设计院加盟分公司,市政设计加盟 | 槽钢冲孔机,槽钢三面冲,带钢冲孔机-山东兴田阳光智能装备股份有限公司 | 气象监测系统_气象传感器_微型气象仪_气象环境监测仪-山东风途物联网 | 微波消解仪器_智能微波消解仪报价_高压微波消解仪厂家_那艾 | 智慧旅游_智慧景区_微景通-智慧旅游景区解决方案提供商 | 机器视觉检测系统-视觉检测系统-机器视觉系统-ccd检测系统-视觉控制器-视控一体机 -海克易邦 | 工业铝型材生产厂家_铝合金型材配件批发精加工定制厂商 - 上海岐易铝业 | 番茄畅听邀请码怎么输入 - Dianw8.com | 一点车讯-汽车网站,每天一点最新车讯! | 深圳市万色印象美业有限公司| 证券新闻,热播美式保罗1984第二部_腾讯1080p-仁爱影院 | 大行程影像测量仪-探针型影像测量仪-增强型影像测量仪|首丰百科 大通天成企业资质代办_承装修试电力设施许可证_增值电信业务经营许可证_无人机运营合格证_广播电视节目制作许可证 | 校车_校车价格_19座幼儿园校车_幼儿园校车_大鼻子校车 | 依维柯自动挡房车,自行式国产改装房车,小型房车价格,中国十大房车品牌_南京拓锐斯特房车 - 南京拓锐斯特房车 | 恒温油槽-恒温水槽-低温恒温槽厂家-宁波科麦仪器有限公司 | 珠海网站建设_响应网站建设_珠海建站公司_珠海网站设计与制作_珠海网讯互联 | 磁粉制动器|张力控制器|气胀轴|伺服纠偏控制器整套厂家--台灵机电官网 | 震动筛选机|震动分筛机|筛粉机|振筛机|振荡筛-振动筛分设备专业生产厂家高服机械 | 电动葫芦|环链电动葫芦-北京凌鹰名优起重葫芦 | 胶水,胶粘剂,AB胶,环氧胶,UV胶水,高温胶,快干胶,密封胶,结构胶,电子胶,厌氧胶,高温胶水,电子胶水-东莞聚力-聚厉胶粘 | 众品家具网-家具品牌招商_家具代理加盟_家具门户的首选网络媒体。 | 高硼硅玻璃|水位计玻璃板|光学三棱镜-邯郸奥维玻璃科技有限公司 高温高压釜(氢化反应釜)百科 | 广州展览制作|展台制作工厂|展览设计制作|展览展示制作|搭建制作公司 | 好物生环保网、环保论坛 - 环保人的学习交流平台 | 上海电子秤厂家,电子秤厂家价格,上海吊秤厂家,吊秤供应价格-上海佳宜电子科技有限公司 | 海水晶,海水素,海水晶价格-潍坊滨海经济开发区强隆海水晶厂 | 苏州伊诺尔拆除公司_专业酒店厂房拆除_商场学校拆除_办公楼房屋拆除_家工装拆除拆旧 | 私人别墅家庭影院系统_家庭影院音响_家庭影院装修设计公司-邦牛影音 | 焊缝跟踪系统_激光位移传感器_激光焊缝跟踪传感器-创想智控 | 东风体检车厂家_公共卫生体检车_医院体检车_移动体检车-锦沅科贸 | 单电机制砂机,BHS制砂机,制沙机设备,制砂机价格-正升制砂机厂家 单级/双级旋片式真空泵厂家,2xz旋片真空泵-浙江台州求精真空泵有限公司 | 一体化污水处理设备,一体化污水设备厂家-宜兴市福源水处理设备有限公司 | 预制围墙_工程预制围墙_天津市瑞通建筑材料有限公司 | 滑板场地施工_极限运动场地设计_滑板公园建造_盐城天人极限运动场地建设有限公司 | 电脑刺绣_绣花厂家_绣花章仔_织唛厂家-[源欣刺绣]潮牌刺绣打版定制绣花加工厂家 | 登车桥动力单元-非标液压泵站-非标液压系统-深圳市三好科技有限公司 |