Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MS Access中的SQL查询变量_Sql_Ms Access - Fatal编程技术网

MS Access中的SQL查询变量

MS Access中的SQL查询变量,sql,ms-access,Sql,Ms Access,为SQL Server编写查询时,可以声明和使用如下变量: declare @test int select @test = max(ID) from MyTable1 update MyTable2 set (...) where ID > @test update MyTable3 set (...) where ID < @test 在为MS Access编写查询时,是否有类似的方法声明和使用变量 我需要用另一个查询的结果填充变量,然后使用该值执行插入/更新操作。查询将从.N

为SQL Server编写查询时,可以声明和使用如下变量:

declare @test int
select @test = max(ID) from MyTable1
update MyTable2 set (...) where ID > @test
update MyTable3 set (...) where ID < @test
在为MS Access编写查询时,是否有类似的方法声明和使用变量

我需要用另一个查询的结果填充变量,然后使用该值执行插入/更新操作。查询将从.NET应用程序运行。

某种程度上

parameters @test int;
select * from MyTable where ID = @test
但是,不能使用set@test=1234,可以在VBA中运行或设置查询时手动输入参数

乔尔科霍恩 在

您可以使用System.Data.OleDb命名空间中的类来查询访问权限 数据库:

进一步注释重新编辑至OP

问题1

update MyTable2 set (...) where ID > (select max(test) from table1)
问题2

update MyTable3 set (...) where ID < (select max(test) from table1)

我需要在查询中填充@test。此外,该查询将从.NET应用程序运行,而不是从VBA运行。如果从NET应用程序运行,则可以添加参数。例如,我认为不可能在Access中将@用作参数名称的前缀。我通常使用:作为前缀,因为它是标准的SQL或arg,因为它在在线论坛中显示得更好;在我看来,删除@似乎给问题蒙上了阴影,尤其是因为它不会破坏任何东西。如果将上述两行粘贴到“查询设计”窗口中,则参数名称中的符号将在保存时删除,int将更改为long,但它将在粘贴时运行。类似地,如果使用这些行作为querydef的基础,则将执行查询。在Access中,您至少有两个查询。
update MyTable3 set (...) where ID < (select max(test) from table1)