問(wèn)題描述
如果長(zhǎng)度是在運(yùn)行時(shí)(例如,在存儲(chǔ)過(guò)程中)指定的,那么創(chuàng)建 varbinary(max)
類(lèi)型的二進(jìn)制零字符串的最優(yōu)雅方法是什么?>
我可以使用 REPLICATE
函數(shù)來(lái)做到這一點(diǎn),但這涉及大量的轉(zhuǎn)換:
CAST(REPLICATE(CAST(CAST(0 AS tinyint) AS varbinary(max)), @size)AS varbinary(max))
(它甚至不適合在線(xiàn)...)有沒(méi)有更好的方法來(lái)做到這一點(diǎn)?
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)建一個(gè)由零組成的二進(jìn)制字符串,長(zhǎng)度可變的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!