Get year and month from SQL

后端 未结 3 772
小鲜肉
小鲜肉 2020-12-22 05:14

I want to know how can I get the year and month into my database. For example, suppose it’s August, 2011. The output that I need is like this: CAB 11 08 001 (CA

3条回答
  •  独厮守ぢ
    2020-12-22 05:38

    SELECT 
        'CAB'
        + RIGHT(YEAR(GetDate()),2)
        + RIGHT('0' + CONVERT(VARCHAR, MONTH(GetDate())),2)
        + Right('00000' + Cast(CurrentNo as varchar(10)), 5)
    

    That might work..

提交回复
热议问题