If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > SELECT DISTINCT trouble

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-24-03, 06:14
song2siren song2siren is offline
Registered User
 
Join Date: Sep 2003
Posts: 3
SELECT DISTINCT trouble

Hello

I'm using the following to populate a drop down list with distinct values from three fields in a SQL database:

<select name="subArea" class="Text">
<option value="" selected></option>
<%
SELECTStmt = "SELECT DISTINCT subjectName,confSubjectArea2,confSubjectArea3 AS t1 "
FROMStmt = "FROM JPL_conf_DetailsView "
ORDERStmt = "ORDER BY t1 "
SQLStmt = SELECTStmt & FROMStmt & ORDERStmt
Set RS = Connection.Execute(SQLStmt)
Do While Not RS.EOF
cfSubject = RS.Fields("t1")
response.write("<option value='" & cfSubject & "'>" & cfSubject & "</option>" & vbCrLf)
RS.MoveNext
Loop
RS.close
%>
</select>

However, this only returns the following:

<select name="subArea" class="Text">
<option value="" selected></option>
<option value=''></option>
<option value=''></option>
<option value=''></option>
<option value=''></option>
<option value=''></option>
<option value=''></option>
<option value=''></option>
<option value=''></option>
<option value='Children (Private Law)'>Children (Private Law)</option>
</select>

It only seems to retrieve the very last value it finds. I'm not sure where I'm going wrong here - any help would be much appreciated.

Thanks
Reply With Quote
  #2 (permalink)  
Old 11-24-03, 16:47
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
try executing the query in the query analyzer and seeing what you are getting returned. Ensure that your data is right. Looking at the code it appears okie.
Reply With Quote
  #3 (permalink)  
Old 11-24-03, 18:03
rnealejr rnealejr is offline
Registered User
 
Join Date: Feb 2002
Posts: 2,232
You are only returning the last field when you issue the:
cfSubject = RS.Fields("t1")

If you are trying to concatenate all fields you can either do it in the sql statement or
cfSubject = RS.Fields(0) & RS.Fields(1) & RS.Fields(2)
Reply With Quote
  #4 (permalink)  
Old 11-24-03, 18:19
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
ahhh,... that makes mroe sense...

so his sql should be something like...

SELECT DISTINCT subjectName + confSubjectArea2 + confSubjectArea3 AS t1 FROM JPL_conf_DetailsView... etc
Reply With Quote
  #5 (permalink)  
Old 11-24-03, 21:59
rnealejr rnealejr is offline
Registered User
 
Join Date: Feb 2002
Posts: 2,232
Depending on what database he is using, the concatenation will vary - but yes.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On