2

If you define a query in Microsoft Access,

For instance,

SELECT * FROM T_Employees t WHERE t.LastName=[LastName]

a popup dialog will display asking you to enter a value for LastName. LastName a named parameter.

Now from here one can also create a view

CREATE VIEW paramTest AS SELECT * FROM T_Employees t WHERE t.LastName=[LastName]

But when calling this view in another query, the parameter is ignored....

So how does one call the view created above from another query and specify the value of the named parameter within that view? (preferably without VBA, I'm trying to use it to write a query involving a view in SQuirreL SQL).

4

2 回答 2

2

CREATE VIEW语句paramTest使用以下 SQL 创建命名查询 :

SELECT *
FROM T_Employees AS t
WHERE (((t.LastName)=[LastName]));

运行该查询时,数据库引擎不会解释[LastName]为参数,因此不会弹出参数对话框,因为参数的名称与字段名称相同。本质上,数据库引擎返回每个LastName字段等于自身的行......所有行。

如果要创建有效的参数查询,请为参数指定一个与数据源中的任何字段名称都不匹配的名称。而且,正如罗恩所说。CREATE VIEW不允许您创建参数查询。但是,您可以使用CREATE PROCEDURE.

CurrentProject.Connection.Execute "CREATE PROCEDURE paramTest " & _
    "(Which_LastName TEXT(255)) AS" & vbCrLf & _
    "SELECT * FROM T_Employees t WHERE t.LastName=[Which_LastName];"
于 2012-10-10T14:49:58.863 回答
0

VIEWS 不允许使用参数。把它们想象成表而不是查询。通常在需要参数时使用存储过程。为了将参数合并到视图中,您必须使用参数值创建一个表并将其包含在 VIEW SQL 中。参数表通常包括一个 USER ID 以避免并发请求冲突。

于 2012-10-10T14:38:30.260 回答