我想在 ms access 2007 数据库查询中声明和设置变量.我想将 2 个数据库查询结果存储在 2 个变量中,因为它们在执行后是整数或字符串类型.我想知道如何声明和设置变量?
I want to declare and set variables in ms access 2007 database query. I want to store 2 database query results in 2 variables because they are integer or string types after execution. I want to know how can I declare and set variables?
SQL server 等价物是这样的
SQL server equivalent would be something like this
declare @var1 varchar(50) set @var1 = 'select * from table' 推荐答案Jet/ACE SQL 不支持此语法.根据您在这里的最终目标,您需要使用 VBA(下面提供的示例)或子查询(如@Thomas 的解决方案)来实现此类功能.
There is no support for this syntax in Jet/ACE SQL. Depending on what your ultimate goal is here, you will need to use either VBA (sample provided below) or subqueries (as in @Thomas's solution) for this type of functionality.
类似以下内容(改编自 Allen Browne 的网站):
Something along the following lines (adapted from Allen Browne's website):
Function DAORecordsetExample() 'Purpose: How to open a recordset and loop through the records.' 'Note: Requires a table named MyTable, with a field named MyField.' Dim rs As DAO.Recordset Dim strSql As String strSql = "SELECT MyField FROM MyTable;" Set rs = CurrentDb.OpenRecordset(strSql) Do While Not rs.EOF Debug.Print rs!MyField rs.MoveNext Loop rs.Close Set rs = Nothing End Function更多推荐
如何在 ms access 2007 查询中声明和设置变量
发布评论