声明 VARBINARY 时使用变量指定“大小" [英] Using variable to specify 'size' when declaring a VARBINARY
本文介绍了声明 VARBINARY 时使用变量指定“大小"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 SQL Server (2008 R2) 中,不要这样做:
In SQL Server (2008 R2), instead of doing this:
DECLARE @testVar VARBINARY(64);
我想这样做:
DECLARE @varSize INT;
SET @varSize = 64;
DECLARE @testVar VARBINARY(@varSize);
但我收到此错误:
'@varSize' 附近的语法不正确.
Incorrect syntax near '@varSize'.
我该如何做这样的事情或强制 SQL 评估 @varSize?
How can I do something like this or force SQL to evaluate @varSize?
推荐答案
对于一个变量,为什么不直接用MAX?
For a variable, why don't you just use MAX?
DECLARE @testVar VARBINARY(MAX);
现在已经不是 70 年代了.您的系统可以处理它.事实上,如果你想做的事情是可能的,我怀疑你这样做会浪费更多的资源,而不是你首先将变量声明为 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.
这篇关于声明 VARBINARY 时使用变量指定“大小"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文