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. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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 | |
|
|