使用循环将数组的所有值输入到SQL查询中。 [英] Using a loop to input all the values of an array into an SQL query.

查看:356
本文介绍了使用循环将数组的所有值输入到SQL查询中。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。我是ASP的新手,我正在开发一个使用ASP和Oracle 9i数据库的应用程序。我有一个表单,允许用户通过从列表框中选择客户端名称来查询数据库,还可以通过选择开始日期和结束日期来设置搜索的时间段。执行查询后,会向客户生成一份表格信函,详细说明在指定时间段内购买的产品,并感谢客户购买并询问客户的反馈意见他们收到的服务。


如果只选择一个客户端,这很好,但是当从数据库中选择多个客户端名称时,我很难绕过必要的逻辑来制作这项工作。有几个问题:


1.客户端的名称存储在表中的两个单独字段中:last_name和first_name。在表单中,这两个字段组合为一个变量:v_name。但是当执行查询时,表单中选择的每个名称都必须分解为两部分,因此WHERE子句将如下所示:

Hi. I am a relative newbie to ASP and I am working on an application that uses ASP and an Oracle 9i database. I have a form that allows the user to query the database by selecting a client name(s) from a listbox and also set a time period for the search by selecting a start date and end date. Once the query is executed a form letter(s) is (are) generated to the client(s) that details the products that have been purchased during the time period specified, and thanks the client for their purchase and asks for feedback on the customer service they received.

This is fine if only one client is being chosen, but when multiple client names are chosen from the database I''m having trouble trying to wrap my head around the necessary logic to make this work. There are a couple of issues:

1. The name of the client is stored in two separate fields in the table: last_name and first_name. In the form, these two fields are combined as one variable: v_name. But when the query is executed, each name selected in the form will have to be broken down into its two parts so the WHERE clause will look like this:

展开 | 选择 | Wrap | 行号

推荐答案

Jaye,


一个部分解决方案是使用除逗号之外的东西来分隔名字和姓氏(逗号用于默认情况下从表单中分隔不同的条目)。即使你不是,你也可以通过两次滚动分割生成的数组:

Jaye,

One partial solution is to use something besides a comma to separate first and last name (the comma is used to separate the different entries from the form by default). Even if you don''t, you can scroll through the split-generated array by twos:

< span class =codeLinkonclick =Blur(this,this.parentNode.parentNode,getChildren(this),true);>展开 | 选择 | Wrap | 行号


谢谢贾里德,我会尝试这个,让你知道它是怎么回事!
Thanks Jared, I will try this and let you know how it goes!


好吧,我试一试,我搞砸了某个地方......或者可能在一些地方。我使用了您建议的代码并出现以下错误:


Microsoft VBScript运行时错误''800a000d''

类型不匹配

我知道这是因为我没有声明变量来将结果记录集保存为数组。我不是100%肯定如何做到这一点,但我会继续努力,如果我仍然无法得到它,我会在这里发布我的代码。我可能在某个地方有一个语法或逻辑错误,我现在看不到。我还必须将日期合并到SQL查询中。用户可以在指定的时间段内生成多个字母 - 开始日期到结束日期。我会看看我是否可以让第一部分工作,然后我会把日期范围放进去。


我会告诉你的。再次感谢你的帮助。


Jaye
Well, I gave it a try and I messed it up somewhere...or probably in a few places. I used the code you suggested and got the following error:

Microsoft VBScript runtime error ''800a000d''
Type mismatch

I know this is because I did not declare the variable to hold the resulting recordset(s) as an array. I''m not 100% sure how to do this, but I''ll keep trying and if I still can''t get it, I''ll post my code here. I might have a syntax or logic error in there somewhere that I just cannot see right now. I have to incorporate the date into the SQL query as well. Users can generate a number of letters in a specified period of time - start date to end date. I''ll see if I can get the first portion to work, and then I''ll put the date range in.

I''ll keep you posted. Thanks again for your help.

Jaye


这篇关于使用循环将数组的所有值输入到SQL查询中。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆