Create a binary string of zeros, with variable length(创建一个由零组成的二进制字符串,长度可变)
问题描述
如果长度是在运行时(例如,在存储过程中)指定的,那么创建 varbinary(max) 类型的二进制零字符串的最优雅方法是什么?>
我可以使用 REPLICATE 函数来做到这一点,但这涉及大量的转换:
CAST(REPLICATE(CAST(CAST(0 AS tinyint) AS varbinary(max)), @size)AS varbinary(max))(它甚至不适合在线...)有没有更好的方法来做到这一点?
EDIT:代码应该适用于 @size >8000.
原始表单
CAST(REPLICATE(CAST(CAST(0 AS tinyint) AS varbinary(max)), @size)AS varbinary(max))仍然最适合我的需求.
What is the most elegant way to create a string of binary zeros, of type varbinary(max), if the length is specified at run time (e.g., in a stored procedure)?
I could do it using the REPLICATE function, but this involves a lot of casting:
CAST(REPLICATE(CAST(CAST(0 AS tinyint) AS varbinary(max)), @size)
AS varbinary(max))
(It doesn't even fit on the line...) Is there a better way to do this?
EDIT: The code should work for @size > 8000.
The original form
CAST(REPLICATE(CAST(CAST(0 AS tinyint) AS varbinary(max)), @size)
AS varbinary(max))
still suits my needs best.
这篇关于创建一个由零组成的二进制字符串,长度可变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:创建一个由零组成的二进制字符串,长度可变
基础教程推荐
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- 在 SQL 中连接多个表 2021-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- 无法解决整理冲突 2021-01-01
- 是否可以执行按位分组功能? 2021-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
