SQL SET 语句
我目前正在提高我的 SQL 知识。目前我正在尝试通过从 select 语句获取值来声明变量。第一个问题:这可能吗?
第二个问题:我有这个 SQL 尝试执行上述操作。我的意图是将 @version_group
设置为 version_replace
所包含的任何内容,这始终是单行、单列结果。
DECLARE @version_group int
SET @version_group = SELECT version_replace FROM users WHERE id=@sid
我怎样才能将其纠正为有效的语法? (假设有可能)
I am currently improving my knowledge of SQL. Currently I am trying to declare a variable by getting a value from a select statement. First Question: Is this possible?
Second Question: I have this SQL attempting to do the above. My intension is to set @version_group
to whatever version_replace
holds, which is always a single row, single column result.
DECLARE @version_group int
SET @version_group = SELECT version_replace FROM users WHERE id=@sid
How can I correct this to valid syntax? (assuming it's possible)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您想要的语法如下,它需要一条您在最初的工作中没有的信息(FROM 子句):
The syntax you want is as follows, it needs one piece of info that you don't have in your original effort though (the FROM clause) :
这是有可能的。就这样做(SQL 2008):
It's possible. Just do (SQL 2008):
不要忘记包含您的数据源(即表、视图,替换上面的
MyVersionTable
)。Don't forget to include your data source (i.e. table, view, replacing
MyVersionTable
above).SELECT @version_group = version_replace FROM YourTable WHERE id=@sid
SELECT @version_group = version_replace FROM YourTable WHERE id=@sid