A Microsoft Office (Excel, Word) forum. OfficeFrustration

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   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Querry with User Input and Search the columns



 
 
Thread Tools Display Modes
  #1  
Old July 7th, 2008, 03:43 AM posted to microsoft.public.access.queries
Mario
external usenet poster
 
Posts: 115
Default Querry with User Input and Search the columns

I want to get the user input and use that string to search if it occurs in
any part of three columns in the table.

For example,

Select ID, Survey_01, Survey_02, Survey_03, ([Enter SurveyNum to be
searched]) As FindSurveyNum Where Instr(Survey_01, FindSurveyNum) 0 OR
Instr(Survey_02, FindSurveyNum) 0 OR Instr(Survey_03, FindSurveyNum) 0

When I executed the above example, it prompts for "Enter SurveyNum to be
searched" multiple times. Is there a way where I could be prompted only once
and use that search string for querrying different columns in the table.

Thanks
  #2  
Old July 7th, 2008, 05:09 AM posted to microsoft.public.access.queries
[email protected]
external usenet poster
 
Posts: 744
Default Querry with User Input and Search the columns

On Jul 6, 9:43*pm, mario wrote:
I want to get the user input and use that string to search if it occurs in
any part of three columns in the table.

For example,

Select ID, Survey_01, Survey_02, Survey_03, ([Enter SurveyNum to be
searched]) As FindSurveyNum Where Instr(Survey_01, FindSurveyNum) 0 OR
Instr(Survey_02, FindSurveyNum) 0 OR Instr(Survey_03, FindSurveyNum) 0

When I executed the above example, it prompts for "Enter SurveyNum to be
searched" multiple times. Is there a way where I could be prompted only once
and use that search string for querrying different columns in the table.

Thanks


Bad design. Stop. Redesign. What happens if you have to add another
question to your survey? Gets messy FAST. Download At Your Survey
from Duane Hookum's website. It is set up properly for querying.

then you could use something like

SELECT RespondentID, QuestionID, Response
FROM Responses
WHERE QuestionID In (1,2,3)
AND Response0
AND SurveryNum = [Enter a Survey Number:];

otherwise, you would have to union query this mess together, and I
spent six months doing that. Total hassle. And completely
avoidable. If you have all the data in the tables already, you could
create a union query out of it and clean up this mess. But
summarizing data like this is difficult, because SQL is not designed
to work across columns as well as it is down columns.
  #3  
Old July 7th, 2008, 12:22 PM posted to microsoft.public.access.queries
John Spencer
external usenet poster
 
Posts: 7,815
Default Querry with User Input and Search the columns

If you cannot change your design then you can try the following query.

Select ID, Survey_01
, Survey_02
, Survey_03
, [Enter SurveyNum to be searched] As FindSurveyNum
WHERE Survey_01 Like "*" & [Enter SurveyNum to be searched] & "*" OR
Survey_02 Like "*" & [Enter SurveyNum to be searched] & "*" OR
Survey_03 Like "*" & [Enter SurveyNum to be searched] & "*"

If this doesn't work then try replacing the asterisks "*" with percent signs "%".

John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County

mario wrote:
I want to get the user input and use that string to search if it occurs in
any part of three columns in the table.

For example,

Select ID, Survey_01, Survey_02, Survey_03, ([Enter SurveyNum to be
searched]) As FindSurveyNum Where Instr(Survey_01, FindSurveyNum) 0 OR
Instr(Survey_02, FindSurveyNum) 0 OR Instr(Survey_03, FindSurveyNum) 0

When I executed the above example, it prompts for "Enter SurveyNum to be
searched" multiple times. Is there a way where I could be prompted only once
and use that search string for querrying different columns in the table.

Thanks

 




Thread Tools
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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 12:01 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.