本文介紹了創(chuàng)建一個由零組成的二進制字符串,長度可變的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
如果長度是在運行時(例如,在存儲過程中)指定的,那么創(chuàng)建 varbinary(max)
類型的二進制零字符串的最優(yōu)雅方法是什么?>
我可以使用 REPLICATE
函數(shù)來做到這一點,但這涉及大量的轉(zhuǎn)換:
CAST(REPLICATE(CAST(CAST(0 AS tinyint) AS varbinary(max)), @size)AS varbinary(max))
(它甚至不適合在線...)有沒有更好的方法來做到這一點?
EDIT:代碼應(yīng)該適用于 @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.
這篇關(guān)于創(chuàng)建一個由零組成的二進制字符串,長度可變的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!