这句是哪里错了,找不到原因啊?

愚者只看星不看答案 2007-09-16 05:56:11
declare @employeesInt int;
set @employeesInt=select count(*) from employees where month(birthdate)=month(getdate());

总是报错如下:
消息 156,级别 15,状态 1,第 2 行
关键字 'select' 附近有语法错误。

高手指点。
...全文
188 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
fengming2222 2007-09-17
  • 打赏
  • 举报
回复
支持yesyesyes的 可以用set 但赋值时要把语句括起来
declare @employeesInt int;
set @employeesInt=(select count(*) from employees where month(birthdate)=month(getdate()));
print @employeesInt
  • 打赏
  • 举报
回复
感谢各位了。结贴。
sunhonglei2004 2007-09-17
  • 打赏
  • 举报
回复
declare @employeesInt int;
select @employeesInt= count(*) from employees where month(birthdate)=month(getdate());
Limpire 2007-09-17
  • 打赏
  • 举报
回复
在想练习键盘指法的情况下,可以这么写,的确没错。
you_tube 2007-09-17
  • 打赏
  • 举报
回复
declare @employeesInt int;
set @employeesInt=(select count(*) from employees where month(birthdate)=month(getdate()));
yesyesyes 2007-09-16
  • 打赏
  • 举报
回复
declare @employeesInt int;
set @employeesInt=(select count(*) from employees where month(birthdate)=month(getdate()));
Limpire 2007-09-16
  • 打赏
  • 举报
回复
简单点:

没有 set ... from ... 这种语法,只有 select ... from ...

为何没有,问微软。
  • 打赏
  • 举报
回复
聚合函数的返回结果是一张表??
这点表示怀疑哦。
zjexe 2007-09-16
  • 打赏
  • 举报
回复
查询语句里边查出来的是一张表,把一个表复制给非表变量
  • 打赏
  • 举报
回复
感谢 zjexe(比正牌多两个横)
为什么set却不行呢?
zjexe 2007-09-16
  • 打赏
  • 举报
回复
改下
declare @employeesInt int;
select @employeesInt=count(*) from employees where datepart(mm,birthdate)=datepart(mm,getdate());
zjexe 2007-09-16
  • 打赏
  • 举报
回复
declare @employeesInt int;
select @employeesInt=count(*) from employees where month(birthdate)=month(getdate());

34,576

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧