jed*_*edu 2 sql-server ms-access
我正在将我的Access查询转换为SQL视图.其中一个Access查询具有用户可以输入值的条件
where table1.id=[Enter the ID of the user]
Run Code Online (Sandbox Code Playgroud)
有没有办法将这样的查询转换为T-SQL.对我来说,保持原样是很重要的.
嗯,首先,没有理由转换为pass-though查询.
但是,SQL Server无法提示您访问(或说使用SQL Server的网站).因此,GUI部分必须由您的网站创建,或者在这种情况下说访问客户端.
通常最好使用按钮构建一些提示表单,因为从UI的角度来看,Access创建的那些自动提示非常糟糕.
如上所述,很可能您只能继续使用访问查询.
但是,如果您需要pt查询,则使用访问代码询问/获取提示值,然后将其添加到查询中.
这将有效:
Dim strSQL As String
Dim invoiceNum As String
strSQL = "select * from tblInvoices where invoiceNumber = "
invoiceNum = InputBox("enter Invoice Number")
If invoiceNum = "" Then Exit Sub
strSQL = strSQL & invoicenumber
With CurrentDb.QueryDefs("qryPassR")
.SQL = strSQL
End With
' now, docmd.OpenReport, or openform or
' whatever it is you wanted to do with the sql
Run Code Online (Sandbox Code Playgroud)
但是,如上所述,对于报告等,我会构建一个允许用户输入值的漂亮表单.查询提示对您的用户来说是纯粹的折磨,并且它们根本不是用户友好的.
此外,以上假设您要打开一些报告,或者其他一些报告.如果需要reocrdset中返回的数据,请使用:
Dim strSQL As String
Dim invoiceNum As String
dim rst As DAO.RecordSet
strSQL = "select * from tblInvoices where invoiceNumber = "
invoiceNum = InputBox("enter Invoice Number")
If invoiceNum = "" Then Exit Sub
strSQL = strSQL & invoicenumber
With CurrentDb.QueryDefs("qryPassR")
.SQL = strSQL
Set rst = .OpenRecordset
End With
Run Code Online (Sandbox Code Playgroud)
最后但并非最不重要的是,正如其他人在此建议的那样,您应该考虑带参数的存储过程,因为上面的内容受SQL注入的影响.
| 归档时间: |
|
| 查看次数: |
78 次 |
| 最近记录: |