User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP section within the Web Development category of DaniWeb, a massive community of 426,308 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,245 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP advertiser: Lunarpages ASP Web Hosting

SQL String question

Join Date: Sep 2007
Posts: 1,057
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 61
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: SQL String question

  #2  
Jan 17th, 2008
Well first thing about your SQL, you have an error near "AND SOURCE IN" because Source is a field but no table is representing that field (address, customer, farmdetails, etc.).

Second, before you run the query, have the webpage spit it out at you so you know exactly how it is being formatted. Just comment out the whole database thing and spit out the SQL statement to make sure. It's good debugging especially when you have it dynamic.

Third, don't use BOF and EOF together because you will create an error, whether or not it happens now or later on. Just stick with EOF.

To do the array you wish, you just post the request.form to a variable, then do the split function to split it at a character, which in this case it would be a comma. then you can do foreach x in arraystring thing exactly how you wish. Example below:
<%
dim strjudet,strcultura,strsursa
dim strculturaarr()

strjudet=request("Judet")
strjudet=Replace(strjudet, ",","','")
strjudet=Replace(strjudet, " ","")
strsursa=request("Sursa")
strsursa=Replace(strsursa, ",","','")
strsursa=Replace(strsursa, " ","")

strcultura=request("Cultura")
''I already declared the variable at the top. This creates the array:
strculturaarr = strcultura.split(",")
''Now to do the for each method BELOW your SQL statement
%>
<%
Set RS = Server.CreateObject("ADODB.Recordset")
RS.ActiveConnection = Conn

SQL = "SELECT * FROM Customer,Address,FarmDetails,InfoDetails WHERE Customer.
ID=Address.ID AND Customer.ID=FarmDetails.ID AND Customer.ID=InfoDetails.ID
AND Address.County IN ('"&strjudet&"') AND REPLACEWITHTABLENAME.Source IN ('"&strsursa&"')"

''Now for the for each method.
for each item in strculturaarr
  SQL = SQL & " AND " & item & ">0"
next
''this will create your SQL statement to have the chosen selection greater than zero.

RS.Open SQL, Conn, 1, 3

''removed the BOF. If you wish, keep it
''If NOT (RS.BOF AND RS.EOF) Then
If NOT RS.EOF Then
%>

<% While (NOT RS.EOF)

%>
Last edited by SheSaidImaPregy : Jan 17th, 2008 at 5:04 pm. Reason: Did array wrong. Fixed it.
Reply With Quote  
All times are GMT -4. The time now is 10:27 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC