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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query to return specific values

Status
Not open for further replies.

RuralCS

Technical User
Feb 22, 2004
12
0
0
US
This is probably a REALLY simple problem, but I'm pretty rusty on SQL. I'm trying to work on someone else's db.

This query is used in a report to display students in a specific Session. Sessions can be numbers, 1, 2, 3... but the field type is set to TEXT.

Here's the SELECT statement:
Code:
SELECT [What session?] AS [session], [last] & ", " & [first] AS Name, [grade1]+Year(Date())-[year1] AS Grade, DLookUp("cvalue","parameters","parameter='weeklytuition'")*weeks([sessions])-DSum("amount","payments","ID=" & [ID])<=0 AS PIF, [Address1] & ", " & [City] & ", " & [State] & " " & [Zip] AS Address, Students.Sessions, Students.[Tel#], Students.School, Students.City
FROM Students
WHERE (((Students.Sessions) [b]LIKE "*" & [What session?] & "*"))[/b]
From the WHERE clause, I want to extract specific values, say everything with "10" in the Sessions field. The problem is that the Sessions field can have multiple entries, such as "2,7,9,10". When I run a report to show all 10's, this query returns all 10's AND all 1's (because of the "*"). If I take out the "*"s, then any row with multiple entries (2,7,9,10) isn't returned.

Any help on how to correct this query?

Thanks in advance
 
This may be a really silly answer :)
I can see three possibilities, if the commas are really there:
Number at beginning of line:
LIKE "" & [What session?] & ",*"
In the middle
LIKE "*," & [What session?] & ",*"
At the end
LIKE "*," & [What session?] & ""

So if these were put together with Or's?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top