create procedure dbo.insertyoutable
  @yourItem1 int,
  @errorinfo varchar(20) output
as  if not exists(select 1 from yourtable where yourYearItem = year(getdate()) and yourMonthItem = your(getdate()))
  begin 
    insert...........
      set @errorinfo  = '保存成功!'
   end
else
 set @errorinfo   = '保存失败!存在相同的记录!'

解决方案 »

  1.   

    create procedure dbo.insertyoutable
      @yourItem1 int,
      @errorinfo varchar(20) output
    as  if not exists(select 1 from yourtable where yourYearItem = year(getdate()) and yourMonthItem = month(getdate()))
      begin 
        insert...........
          set @errorinfo  = '保存成功!'
       end
    else
     set @errorinfo   = '保存失败!存在相同的记录!'
      

  2.   

    select cars_car_price from t_cars_price where to_char(time, 'yyyy-mm') = to_char(system_time, 'yyyy-mm')
    time为数据库时间字段名 syetem_time为取得的当前系统时间变量,格式均为(年,月,日,时,分,秒)
    执行报错为:to_char为不可识别函数名,
    请大家帮个忙了,要用什么函数呢
      

  3.   

    select cars_car_price from t_cars_price where DATEPART(Year,time)=Datepart(Year,system_Time) and DATEPART(Month,time)=Datepart(Month,system_Time)