Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

store a do while loop result set into one variable 2

Status
Not open for further replies.

craigward

Programmer
Nov 13, 2007
230
GB
Hi, Is it possible to store a do while loop result set into one variable. If i response.write SMSResults var below it loops through and gives me the rows i expect to see based on my query but when i want to take the results in one variable outside the loop i just get one row... Any help would be appreciated.

Thanks

Code:
			qryAvailabilityCheck = "SELECT Top 8 company, type, phone, postcode FROM wce_contact WHERE Rooms = '1' AND Postcode <> '' AND idstatus = 'Property' AND Postcode LIKE '%"& MessageTextPcodeorPhone &"%' OR phone LIKE '%"& MessageTextPcodeorPhone &"%' ORDER BY NEWID()"	
			Set oRsAvailability = connStr.Execute(qryAvailabilityCheck)			
			'response.write(qryAvailabilityCheck)&"<br/>"
			'response.end


				Do While Not oRsAvailability.eof	
				
					'Items to send to Enquiries
					company = oRsAvailability("company")
					PropertyType = oRsAvailability("type")
					phone = oRsAvailability("phone")
					
					SMSResults=(company)&" "&(propertytype)&" "&(phone)&"<br/>"
					response.write(SMSResults)
					'response.end
				
				oRsAvailability.MoveNext
				Loop
 
try this:

Code:
SMSResults = ""
Do While Not oRsAvailability.eof    
                
                    'Items to send to Enquiries
                    company = oRsAvailability("company")
                    PropertyType = oRsAvailability("type")
                    phone = oRsAvailability("phone")
                    
                    SMSResults= SMSResults & " " & (company)&" "&(propertytype)&" "&(phone)&"<br/>"
                    response.write(SMSResults)
                    'response.end
                
                oRsAvailability.MoveNext
                Loop

Although, there is probably a more elegant way to handle whatever you're trying to accomplish than a large, space separated variable. If you care to share your ultimate goal, perhaps we could help out a bit more.


.mark.


 
Code:
SMSResults = ""
thisResult = ""

Do While Not oRsAvailability.eof    
	'Items to send to Enquiries
	company = oRsAvailability("company")
	PropertyType = oRsAvailability("type")
	phone = oRsAvailability("phone")
	thisResult = company & " " & propertytype & " "& phone & vbcrlf
	SMSResults = SMSResults & thisResult
	response.write thisResult & "<br />"
	'response.end
	oRsAvailability.MoveNext
Loop

in the end, SMSResults will have all the records with each one separated by a newline character. You can still display each one on the screen using the "thisResult" variable.

But going back to Mark's post - what exactly are you trying to acheive, there might be a better way to get to your final goal.

TIP: trying googling the answer before posting, you'll find that more times than not someone else somewhere has had the same request and posted an answer online.
----
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javascript enabled browsers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top