@RowFrom int
@RowTo int
是存储过程的全局输入参数,因为我使用T-SQL编译存储过程内的SQL查询,然后Exec(@sqlstatement)在存储过程的末尾使用它来显示结果,当我尝试使用它时,它会给我这个错误在执行的变量中@RowFrom或者@RowTo内部@sqlstatement..否则工作正常..请帮助.
"Must declare the scalar variable "@RowFrom"."
Run Code Online (Sandbox Code Playgroud)
另外,我尝试在@sqlstatement变量中包含以下内容:
'Declare @Rt int'
'SET @Rt = ' + @RowTo
Run Code Online (Sandbox Code Playgroud)
但@RowTo仍然没有将其值传递给@Rt 并生成错误.
我正在尝试批处理一些SQL脚本.在顶部,我已经宣布了一些我认为在术语意义上的全局变量
所以:
DECLARE @someVar1
DECLARE @someVar2
...etc.
GO
Some batch of SQL here that sets @someVar1 and @SomeVar2 to a value and uses it in the SQL statement
GO
Some batch of SQL here that sets @someVar1 and @SomeVar2 to a value and uses it in the SQL statement
GO
...
Run Code Online (Sandbox Code Playgroud)
声明超出范围...意味着当我运行它时,后续批处理脚本找不到那些声明.有没有办法让所有使用或设置这些变量的批处理脚本都使用全局?
有没有办法从变量中选择数据库?
Declare @bob as varchar(50);
Set @bob = 'SweetDB';
GO
USE @bob
Run Code Online (Sandbox Code Playgroud)