SQL:整数日期的下一个月,并返回一个整数

SQL:整数日期的下一个月,并返回一个整数,sql,sybase,Sql,Sybase,我有一列startMonth作为整数,例如199812 我需要它的下一个月并返回一个整数199901。如何在SQL中一行处理这个问题 近似 SELECT NEXTMONTH(199812) 将显示199901不确定sybase语法,但我的方法是: select case when startMonth % 100 = 12 then startMonth - 11 + 100 else startMonth + 1 end 将整数

我有一列startMonth作为整数,例如
199812

我需要它的下一个月并返回一个整数
199901
。如何在SQL中一行处理这个问题

近似

SELECT NEXTMONTH(199812)

将显示
199901

不确定sybase语法,但我的方法是:

select case when startMonth % 100 = 12
            then startMonth - 11 + 100
            else startMonth + 1
       end
  • 将整数转换为字符串
  • 在末尾附加01
  • 把结果推迟到某个日期
  • 加一个月
  • 提取年份和月份,并将其转换为字符串
  • 将其合成,然后将其转换为int

  • 您正在运行什么RDBMS?我已经更新了问题,它正在Sybase中运行什么Sybase产品?ASE?SQLAnywhere?我试过并成功了:CAST(CONVERT(CHAR(8),DATEADD(VARCHAR,startMonth*100+1)),112)AS INT/100当startMonth%12=0时的
    应该是:
    当startMonth%100=12
    不起作用,
    201408%12=0
    我试过并成功了:CAST(CONVERT(CHAR(8),DATEADD(VARCHAR,startMonth*100+1)),112)AS INT/100