本文介紹了創建一個由零組成的二進制字符串,長度可變的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
如果長度是在運行時(例如,在存儲過程中)指定的,那么創建 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.
這篇關于創建一個由零組成的二進制字符串,長度可變的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!