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
still suits my needs best.
Better or just shorter? :)