我正在尝试对我的服务器进行简单查询,并希望将结果存储在变量 @times 中.
I am trying to make a simple query to my server and want the result to be stored in the variable @times.
DECLARE @times int
SET @times = SELECT COUNT(DidWin)as "I Win"
FROM thetable
WHERE DidWin = 1 AND Playername='Me'
IntelliSense 说 Select 附近的语法错误
IntelliSense says Wrong syntax near Select
你只需要在你的选择周围加上括号:
You just need parentheses around your select:
SET @times = (SELECT COUNT(DidWin) FROM ...)
或者你可以这样做:
SELECT @times = COUNT(DidWin) FROM ...
这篇关于sql 使用 COUNT 设置变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!