我想在 ms access 2007 数据库查询中声明和设置变量。我想将2个数据库查询结果存储在2个变量中,因为执行后它们是整数或字符串类型。我想知道如何声明和设置变量?
SQL Server 等效项是这样的
declare @var1 varchar(50)
set @var1 = 'select * from table'
没有对此的支持syntax在 Jet/ACE SQL 中。根据您的最终目标,您将需要使用 VBA(下面提供的示例)或子查询(如 @Thomas 的解决方案)来实现此类功能。
大致如下(改编自艾伦·布朗的网站 http://allenbrowne.com/func-DAO.html#DAORecordsetExample):
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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)