Using variable to specify 'size' when declaring a VARBINARY

試著忘記壹切 提交于 2019-12-01 19:12:08

问题


In SQL Server (2008 R2), instead of doing this:

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:

Incorrect syntax near '@varSize'.

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


回答1:


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

DECLARE @testVar VARBINARY(MAX);

This isn't the 70s anymore. Your system can handle it. In fact if what you want to do were possible, I suspect you'd waste more resources doing that than you would just declaring the variable as MAX in the first place.



来源:https://stackoverflow.com/questions/12426756/using-variable-to-specify-size-when-declaring-a-varbinary

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!