Using a variable to indicate "size" when declaring VARBINARY

In SQL Server (2008 R2) instead:

DECLARE @testVar VARBINARY(64); 

I would like to do this:

 DECLARE @varSize INT; SET @varSize = 64; DECLARE @testVar VARBINARY(@varSize); 

But I get this error:

Invalid syntax near '@varSize'.

How can I do something like this or get SQL to evaluate @varSize?

+4
source share
1 answer

For a variable, why don't you just use MAX?

 DECLARE @testVar VARBINARY(MAX); 

This is not the 70s. Your system can handle this. In fact, if what you want to do was possible, I suspect that you are spending more resources on this than simply declaring the MAX variable in the first place.

+8
source

Source: https://habr.com/ru/post/1434226/


All Articles