语句大意是
增加某时间列的1个月份-
时间列=dateadd(M,1,时间列)
条件是时间列的月份没在一个字符串中
where MONTH(时间列) not in (条件字符串)
例如:条件字符串为"1,2,3,4,5,6"
可not in两侧数据类型不符.
最好不要将条件字符串读出处理
怎么平衡这个问题,谢谢大家来帮忙,来发表发表意见和建议!!!!!

解决方案 »

  1.   

    declare @sql varchar(8000)
    set @sql = 
    '增加某时间列的1个月份-
    时间列=dateadd(M,1,时间列)
    条件是时间列的月份没在一个字符串中
    where MONTH(时间列) not in ('+条件字符串')'
      

  2.   

    declare @sql varchar(8000)
    set @sql = 
    '增加某时间列的1个月份-
    时间列=dateadd(M,1,时间列)
    条件是时间列的月份没在一个字符串中
    where MONTH(时间列) not in ('+条件字符串')'exec(@sql)
      

  3.   

    declare @sql varchar(8000)
    set @sql = 
    '增加某时间列的1个月份-
    时间列=dateadd(M,1,时间列)
    条件是时间列的月份没在一个字符串中
    where MONTH(时间列) not in ('+条件字符串+')'exec(@sql)
      

  4.   

    yrwx001()
    能不能详细说明一下,是使用加号吗?
    后面的字符串能变成整型数组吗?
    等待您的回复,谢谢!!!
      

  5.   

    /*
    条件字串全部用逗号分割,包括最后一个,例如:
    '1,3,5,7,9,11,'
    */
    update 表 set 某时间列 = dateadd(month, 1, 某时间列) where charindex(cast(datepart(month, 某时间列) as varchar(2))+',', '条件字符串') = 0
      

  6.   

    有返回字符型的datename()函数:
    select datename(month,getdate())
    --返回08:前面的0和日期格式设置有关。
      

  7.   

    這樣寫吧
    update 表 set 某时间列 = dateadd(month, 1, 某时间列) where charindex(','+cast(datepart(month, 某时间列) as varchar(2))+',', ','+'条件字符串'+',') = 0