如何在 SQL 中翻转随机位
出于测试目的,我想通过将列中的位设置为随机值来更新表。
update [Planned]
set [IsPlannable] = 1 * rand(cast(cast(newid() as binary(8)) as int))
WHERE [ComputerID] > 100
它似乎确实按其应有的方式工作,但不是我想要的方式。我猜问题是结果大多数时候都会高于 1。
如何翻转随机位为随机值?
For testing purposes I want to update a table by setting bits in colums to a random value.
update [Planned]
set [IsPlannable] = 1 * rand(cast(cast(newid() as binary(8)) as int))
WHERE [ComputerID] > 100
It does seem to work as it should but not the way I want it. I guess the problem is the result will most of the time be higher than 1.
How can I flip random bits to random values?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
1 *
仍然产生一个小数 &鉴于cast(0.1 as bit)
将产生 1,cast(0.9 as bit)
更新也将全部设置为 1。
The
1 *
is still yielding a fractional number & given thatcast(0.1 as bit)
will yeild 1 as willcast(0.9 as bit)
the updates are all set to 1.You could;
根据您必须使用的位字段数量,您可以使用如下方式生成所有可能的设置:
Depending upon how many bit fields you have to use, you can generate all of the possible settings using something like this:
怎么样
How about