declare @employeesInt int;
set @employeesInt=select count(*) from employees where month(birthdate)=month(getdate());总是报错如下:
消息 156,级别 15,状态 1,第 2 行
关键字 'select' 附近有语法错误。高手指点。

解决方案 »

  1.   

    declare @employeesInt int;
    select @employeesInt=count(*) from employees where month(birthdate)=month(getdate());
      

  2.   

    改下
    declare @employeesInt int;
    select @employeesInt=count(*) from employees where datepart(mm,birthdate)=datepart(mm,getdate());
      

  3.   

    感谢 zjexe(比正牌多两个横)
    为什么set却不行呢?
      

  4.   

    简单点:没有 set ... from ... 这种语法,只有 select ... from ...为何没有,问微软。
      

  5.   

    declare @employeesInt int;
    set @employeesInt=(select count(*) from employees where month(birthdate)=month(getdate()));
      

  6.   

    支持yesyesyes的 可以用set 但赋值时要把语句括起来
    declare @employeesInt int;
    set @employeesInt=(select count(*) from employees where month(birthdate)=month(getdate()));
    print @employeesInt
      

  7.   

    declare @employeesInt int;
    set @employeesInt=(select count(*) from employees where month(birthdate)=month(getdate()));
      

  8.   

    declare @employeesInt int;
    select @employeesInt= count(*) from employees where month(birthdate)=month(getdate());